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.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!
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
}
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();
}
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
}
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
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.