Hello everyone,
I'm very new to Arduino, but I decided to start a small project anyway. The hardware part was easy (attachment) - 12 buttons, 8 switches and a key, built on Arduino Micro.
So far I connected 12 buttons directly from ground to pin 1-12, using the internal pullup resistor.
I used the Arduino Joystick Library to make it look like a game device and uploaded JoystickButton.ino example and the 4 buttons work like they should.
I'm unsure about modifying this line completely - no other help than the commented line ...
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;
Other then that I guess I should modify the rest to reflect the amount of buttons/switches, but when I change those numbers, the game device panel starts flickering and some buttons stay pressed (see attachment2)
// Based on example
// by Matthew Heironimus
// 2015-11-20
//--------------------------------------------------------------------
#include <Joystick.h>
void setup() {
// Initialize Button Pins
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);
// Initialize Joystick Library
Joystick.begin();
}
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;
// Last state of the button
int lastButtonState[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
void loop() {
// Read pin values
for (int index = 0; index < 12; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}
Even at this state the 4 buttons (pin 9,10,11,12) still work like they are supposted to.
What am I doing wrong?
And another (optional) question - what can I do to optimize the game device to only have the 20 buttons/switches, no rudder/thruster/axis/hat options. This doesn't bother me much though, functionality needs to be resolved first ![]()
Thank's for any insight!

