Teensy 2.0 Programming... v1.5

Various user-contributed guides for software-related things
ZarkWizard
Posts: 18
Joined: Sun Jan 01, 2017 9:46 am
Been thanked: 4 times

Re: Teensy 2.0 Programming... v1.5

Post by ZarkWizard » Sat Mar 25, 2017 8:18 am

jellypowered wrote:So i'm using this code with my setup. I debugged the buttons, all is well, the horizontals are inverted but setting up the controller config upon initial install lets me avoid complications.

I have a question,
[spoiler="Debug Outputs"]// ------------- Left Side
// Joystick Digital Buttons
const int DirUp = 11;
const int DirDown = 22;
const int DirLeft = 12;
const int DirRight = 13;

// Left Side Top Buttons
const int ButL = 15;
const int ButZL = 14;

// ------------- Right Side
const int ButX = 7;
const int ButY = 0;
const int ButB = 3;
const int ButA = 6;
const int ButStart = 1; // Plus
const int ButSelect = 2; // Minus

//Right Side Top Buttons
const int ButR = 4;
const int ButZR = 5;

// ------------- Bottom Row
const int ButHome = 8;
const int ButTV = 9;
const int ButPower = 10;

// ---------------------------
//ANALOG CONTROLLERS REQUIRE ANALOG INPUT MAPPING A0-A10 Teensy 2.0
// ---------------------------

// ------------- Right Stick
// Joystick Analog Buttons
const int JoyRClick = 19; // Click is a digital mapping
const int JoyRVert = 20; // Analog Mapping A1
const int JoyRHorz = 21; // Analog Mapping A0

// ------------- Left Stick
const int JoyLClick = 18; // Click is a digital mapping
const int JoyLVert = 17; // Analog Mapping A4
const int JoyLHorz = 16; // Analog Mapping A5[/spoiler]
I don't have power and tv hooked up. I did wire the home button to "D2" which shows up in debug as "8"

Can I use home as the "mode switching"
How hard is this to change in the code? I am not a programmer but I can follow instructions.

Thanks!
Ok.. So you want to switch modes.. You should be able to set ButHome and ButPower to whatever you want. Just keep in mind if you set them to a specific button on the controller the controller will see that as a mode setting button. You won't be able to use it in any games.

If you want to disable something you would do it on the main loop where it looks for those buttons:
[spoiler="Main Code Loop"]

Code: Select all

void loop() {

#ifdef DEBUG_BUTTONS
      loop_keyboarddebug();
#else 
// Power button is used to look for toggle mode.  If you have the power button held down
// the teensy will look for either the left or right stick press to change modes.
// if you are not holding down power, things will work normally
  tbut = digitalRead(ButPower);
  int hbut = digitalRead(ButHome);

  if (tbut == LOW) {
    SetButtonState();
    SetGameState();
    MAMECheck();
  }
  
  if (hbut == LOW) {
    // Enter specific keys while home button is pressed
    HomeCombo();
#ifdef MODE_LED_USED
       // We want to turn off the LED, it was just on.
      if (LIGHT_HOME && Lasthbut != hbut) {
          digitalWrite(FLASH_PIN, HIGH);    // turn the LED on by making the voltage HIGH
      }
      Lasthbut = hbut;
#endif
  }

#ifdef MODE_LED_USED
  if (hbut == HIGH) {
    // We want to turn off the LED, it was just on.
    if (LIGHT_HOME && Lasthbut != hbut) {
        digitalWrite(FLASH_PIN, LOW);    // turn the LED off by making the voltage LOW
    }
    Lasthbut = hbut;
    
  }
#endif

  if (tbut == HIGH && hbut == HIGH) {  // If either is LOW we are doing a mode change so don't call these..
     if (CurrentState)
      loop_joystick();
    else
      loop_keyboard();
  }
#endif
}
[/spoiler]
If you want to remove the Power Button functions comment out the section:
[spoiler="Power Button Section"]

Code: Select all

if (tbut == LOW) {
    SetButtonState();
    SetGameState();
    MAMECheck();
  }
[/spoiler]
If you want to remove the Home Button functions comment out the section:
[spoiler="Power Button Section"]

Code: Select all

if (hbut == LOW) {
    // Enter specific keys while home button is pressed
    HomeCombo();
#ifdef MODE_LED_USED
       // We want to turn off the LED, it was just on.
      if (LIGHT_HOME && Lasthbut != hbut) {
          digitalWrite(FLASH_PIN, HIGH);    // turn the LED on by making the voltage HIGH
      }
      Lasthbut = hbut;
#endif
  }
[/spoiler]
If you are just looking to remap the button to something else just set the button to whatever you want to map to. As long as the variable is set to the proper key the code will function.

The only question I have is on your Analog buttons you have them defined as digital buttons. Was that on purpose? If you look at the Teensy the analogs should be mapped as 0-11. eg: (using your code - changed to analog mapping
[spoiler="Analog Mapping"]

Code: Select all

// ------------- Right Stick
// Joystick Analog Buttons
const int JoyRClick = 19; // Click is a digital mapping
const int JoyRVert = 1; // Analog Mapping A1
const int JoyRHorz = 0; // Analog Mapping A0

// ------------- Left Stick
const int JoyLClick = 18; // Click is a digital mapping
const int JoyLVert = 4; // Analog Mapping A4
const int JoyLHorz = 5; // Analog Mapping A5
[/spoiler]
Maybe it works with the bigger #s since they are over 11.. I have never tried.

Did I help or confuse things even more? If I can clarify something let me know.

User avatar
Marty33
Posts: 145
Joined: Wed Feb 22, 2017 4:55 pm
Has thanked: 19 times
Been thanked: 13 times

Re: Teensy 2.0 Programming... v1.5

Post by Marty33 » Tue Jun 13, 2017 11:53 am

Hello @ZarkWizard.

Big big thanks for your work.

I work on the Wii U project. I'll take your code on the first post. It's the last version ?

With it, i made this :
Image

I made mistake ? :P

umrotzer
Posts: 12
Joined: Wed Jun 07, 2017 7:43 pm
Been thanked: 1 time

Re: Teensy 2.0 Programming... v1.5

Post by umrotzer » Mon Jan 08, 2018 5:28 am

First I hope anyone answer xd.

I tested banjos original code and get nearly no io, then I used this code and all good expect for invert.

So if u use retroarch "inbuilt/ported" lib emus all good, because u can select all buttons manually. But if u use other emus, like reicast or mupen64, ppsspp aso or navigate on retroarch Linux menu the left stick is inverted.

I know u can change true to false inside the code but that change nothing still all the same.

Also specially for reicast u get another problem in case the teensy input is detected as to controllers @ same time inside retroarch (Joystick and keyboard)

I used the latest adruino software with latest teensy libs aso and burnt the teensy as mouse/keyboard/joystick.

Anyone an idea?

umrotzer
Posts: 12
Joined: Wed Jun 07, 2017 7:43 pm
Been thanked: 1 time

Re: Teensy 2.0 Programming... v1.5

Post by umrotzer » Mon Jan 15, 2018 8:18 am

Push

Flying_Lizard
Posts: 6
Joined: Thu May 24, 2018 3:37 am

Re: Teensy 2.0 Programming... v1.5

Post by Flying_Lizard » Thu May 24, 2018 11:39 am

1. Dose the home button have the same results as pressing the hotkey + select on a keyboard ie. will it exit the rom/game I’m playing?
2. I want to add two touch pad switches, one for “Save” and the other for “Load”. I’ve done it before using a relay to trigger two keys together but that was because I was using a pcb out of a 2.4Ghz keyboard to make a wireless sega controller for retropie. But now I’m using a teensy in my Wii U Pi and was wondering in I could do it in the code.
Is there a command for load and save and how would I use it?
I will try it on a teensy 2.0++ as I need the extra pins

djobbydjobba
Posts: 9
Joined: Tue Mar 26, 2019 6:45 am
Has thanked: 2 times
Been thanked: 1 time

Re: Teensy 2.0 Programming... v1.5

Post by djobbydjobba » Sat May 04, 2019 7:45 am

Hi there. I don't if this topic is still up... Anyway I use your code, and thank you so much for it. I was wondering if I could add two more hotkeys with your shift function ? The idea is to press the shift key (tv button in my case as power is isolated and used for switching on and off) and minus and plus for sound control... does anyone know how to do that ?

djobbydjobba
Posts: 9
Joined: Tue Mar 26, 2019 6:45 am
Has thanked: 2 times
Been thanked: 1 time

Re: Teensy 2.0 Programming... v1.5

Post by djobbydjobba » Sun May 12, 2019 5:24 pm

umrotzer wrote:
Mon Jan 08, 2018 5:28 am
First I hope anyone answer xd.

I tested banjos original code and get nearly no io, then I used this code and all good expect for invert.

So if u use retroarch "inbuilt/ported" lib emus all good, because u can select all buttons manually. But if u use other emus, like reicast or mupen64, ppsspp aso or navigate on retroarch Linux menu the left stick is inverted.

I know u can change true to false inside the code but that change nothing still all the same.

Also specially for reicast u get another problem in case the teensy input is detected as to controllers @ same time inside retroarch (Joystick and keyboard)

I used the latest adruino software with latest teensy libs aso and burnt the teensy as mouse/keyboard/joystick.

Anyone an idea?
Same issue here... have you found something ? Inversion works for me except for left stick horizontal. Weird.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest