Description of Issue
I'm making a game controller consisting of 12 buttons and 8 switches. The Arduino Micro I'm using has 20 pins that should be able to be used as digital input, which is just perfect.
The "JoystickButton" example works as intended for pins 9-12. I extended the example to use all 20 pins, however only pins 0-13 work, no response from pins 14-19.
Technical Details
- Arduino Board: Arduino Micro
- Host OS: Windows 7
- Arduino IDE Version: 1.8.7
Sketch File that Reproduces Issue
#include <Joystick.h>
Joystick_ Joystick;
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
Joystick.begin();
}
const int pinToButtonMap = 0;
int lastButtonState[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void loop() {
for (int index = 0; index < 20; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}
Wiring Details
using internal pullup resitor, all buttons/switches are connected GND->button->pinX
After some more testing I found the analog pins A0-A5 actually do work, but only alone and when adressed as A0-A5, not 14-19 as in following example:
...
void setup() {
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
Joystick.begin();
}
const int pinToButtonMap = A0;
int lastButtonState[6] = {0,0,0,0,0,0};
void loop() {
for (int index = 0; index < 6; index++)
...
Using both 0-13 and A0-A5 gives randomly blinking or lit buttons, using 0-19 ignores 14-19.
What am I doing wrong?