Hi Banjokazooie ! I have just finished my build and I'm using your code. I experience a strange behavior with the analog sticks. My left stick works flawless, up and down on the right stick too but left and right are recognised like left and right of the other stick...
My first thought was a bad solder that could be in contact with another pin, resoldered everything, same result.
Then I took an analog stick from another spare working wiiU gamepad, same result.
Then I used a brand new teensy, same result.
Then I tried different analog pins on the teensy and changed the code accordingly, same result...
It's driving me ****ing crazy ! Needless to say I double checked any short with my controller...
Have any of you heard about such a thing ? I'm lost !
Here is my actual code:
const int MODE = 8; // the pin that the pushbutton is attached to
const int LED = 23;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;
void setup() {
pinMode(15, INPUT_PULLUP); // 01 Left Shoulder
pinMode(14, INPUT_PULLUP); // 02 Lelf Trigger
pinMode(13, INPUT_PULLUP); // 03 Right
pinMode(12, INPUT_PULLUP); // 04 Left
pinMode(11, INPUT_PULLUP); // 05 Up
pinMode(22, INPUT_PULLUP); // 06 Down
pinMode(3, INPUT_PULLUP); // 07 B
pinMode(6, INPUT_PULLUP); // 08 A
pinMode(5, INPUT_PULLUP); // 09 Right Trigger
pinMode(LED, OUTPUT); // LED
pinMode(1, INPUT_PULLUP); // 13 Start
pinMode(2, INPUT_PULLUP); // 14 Select
pinMode(0, INPUT_PULLUP); // 15 Y
pinMode(MODE, INPUT_PULLUP); // HOME Button
pinMode(20, INPUT_PULLUP); // 19 Left Joystick Button
pinMode(21, INPUT_PULLUP); // 20 Right Joystick Button
pinMode(4, INPUT_PULLUP); // 23 Right Shoulder
pinMode(7, INPUT_PULLUP); // 24 X
pinMode(9, INPUT_PULLUP); // TV Button
// Serial.begin(9600);
}
void loop_joystick() {
if (digitalRead(0) == LOW)
{
Joystick.button(15, 1);
}
else
{
Joystick.button(15, 0);
}
if (digitalRead(1) == LOW)
{
Joystick.button(13, 1);
}
else
{
Joystick.button(13, 0);
}
if (digitalRead(2) == LOW)
{
Joystick.button(14, 1);
}
else
{
Joystick.button(14, 0);
}
if (digitalRead(3) == LOW)
{
Joystick.button(7, 1);
}
else
{
Joystick.button(7, 0);
}
if (digitalRead(4) == LOW)
{
Joystick.button(23, 1);
}
else
{
Joystick.button(23, 0);
}
if (digitalRead(5) == LOW)
{
Joystick.button(9, 1);
}
else
{
Joystick.button(9, 0);
}
if (digitalRead(6) == LOW)
{
Joystick.button(8, 1);
}
else
{
Joystick.button(8, 0);
}
if (digitalRead(7) == LOW)
{
Joystick.button(24, 1);
}
else
{
Joystick.button(24, 0);
}
if (digitalRead(9) == LOW)
{
Keyboard.press(KEY_ESC);
}
else
{
Keyboard.release(KEY_ESC);
}
if (digitalRead(11) == LOW)
{
Joystick.button(5, 1);
}
else
{
Joystick.button(5, 0);
}
if (digitalRead(12) == LOW)
{
Joystick.button(4, 1);
}
else
{
Joystick.button(4, 0);
}
if (digitalRead(13) == LOW)
{
Joystick.button(3, 1);
}
else
{
Joystick.button(3, 0);
}
if (digitalRead(14) == LOW)
{
Joystick.button(2, 1);
}
else
{
Joystick.button(2, 0);
}
if (digitalRead(15) == LOW)
{
Joystick.button(1, 1);
}
else
{
Joystick.button(1, 0);
}
if (digitalRead(20) == LOW)
{
Joystick.button(19, 1);
}
else
{
Joystick.button(19, 0);
}
if (digitalRead(21) == LOW)
{
Joystick.button(20, 1);
}
else
{
Joystick.button(20, 0);
}
if (digitalRead(22) == LOW)
{
Joystick.button(6, 1);
}
else
{
Joystick.button(6, 0);
}
int rX = analogRead(5);
rX = (rX - 512) * 1.8 + 512;
if (rX > 1023)
rX=1023;
if (rX < 0)
rX = 0;
int rY = analogRead(4);
rY = (rY - 512) * 1.8 + 512;
if (rY > 1023)
rY=1023;
if (rY < 0)
rY = 0;
rY=abs(1023-rY);
int rL = analogRead(2);
rL = (rL - 512) * 1.8 + 512;
if (rL > 1023)
rL=1023;
if (rL < 0)
rL = 0;
int rR = analogRead(3);
rR = (rR - 512) * 1.8 + 512;
if (rR > 1023)
rR=1023;
if (rR < 0)
rR = 0;
//rR=abs(1023-rR);
Joystick.X(rX);
Joystick.Y(rY);
Joystick.sliderLeft(rL);
Joystick.sliderRight(rR);
}
void loop_keyboard() {
if (digitalRead(11) == LOW)
{
Keyboard.press(KEY_UP);
}
else
{
Keyboard.release(KEY_UP);
}
if (digitalRead(22) == LOW)
{
Keyboard.press(KEY_DOWN);
}
else
{
Keyboard.release(KEY_DOWN);
}
if (digitalRead(12) == LOW)
{
Keyboard.press(KEY_LEFT);
}
else
{
Keyboard.release(KEY_LEFT);
}
if (digitalRead(13) == LOW)
{
Keyboard.press(KEY_RIGHT);
}
else
{
Keyboard.release(KEY_RIGHT);
}
//buttons
if (digitalRead(15) == LOW)
{
Keyboard.press(KEY_ENTER);
}
else
{
Keyboard.release(KEY_ENTER);
}
if (digitalRead(14) == LOW)
{
Keyboard.press(KEY_ESC);
}
else
{
Keyboard.release(KEY_ESC);
}
if (digitalRead(4) == LOW)
{
Keyboard.press(KEY_LEFT_CTRL);
}
else
{
Keyboard.release(KEY_LEFT_CTRL);
}
if (digitalRead(5) == LOW)
{
Keyboard.press(KEY_LEFT_ALT);
}
else
{
Keyboard.release(KEY_LEFT_ALT);
}
if (digitalRead(6) == LOW)
{
Keyboard.press(KEY_A);
}
else
{
Keyboard.release(KEY_A);
}
if (digitalRead(3) == LOW)
{
Keyboard.press(KEY_B);
}
else
{
Keyboard.release(KEY_B);
}
if (digitalRead(0) == LOW)
{
Keyboard.press(KEY_Y);
}
else
{
Keyboard.release(KEY_Y);
}
if (digitalRead(7) == LOW)
{
Keyboard.press(KEY_X);
}
else
{
Keyboard.release(KEY_X);
}
if (digitalRead(1) == LOW)
{
Keyboard.press(KEY_F12);
}
else
{
Keyboard.release(KEY_F12);
}
if (digitalRead(2) == LOW)
{
Keyboard.press(KEYPAD_5);
}
else
{
Keyboard.release(KEYPAD_5);
}
}
void loop() {
buttonState = digitalRead(MODE);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
// Serial.println("on");
// Serial.print("number of button pushes: ");
// Serial.println(buttonPushCounter);
}
else {
// Serial.println("off");
}
}
lastButtonState = buttonState;
if (buttonPushCounter % 2 == 0) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
if (digitalRead(LED) == LOW)
{
loop_joystick();
}
else
{
loop_keyboard();
}
}