// Arduino Pro Micro Digital Pins
// Arduino Joystick
// NOTE: This sketch file is for use with Arduino Pro Micro only.
// CODE BY LONGLO (JOLIMS.COM)
// May 8, 2022
//--------------------------------------------------------------------
#include
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,5,0,true,false,false,false,false,false,false,false,false,false,false);
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);
Joystick.begin();
Joystick.setXAxisRange(-1, 1);
}
int lastButtonState[7] = {0};
int buttonMap[18] = {1,0,2,3,4,5,6,7};
void loop() {
for (int index = 0; index < 7; index++)
{
int currentButtonState = !digitalRead(buttonMap[index]);
if (currentButtonState != lastButtonState[index])
{
switch (index) {
case 0:
Joystick.setButton(0, currentButtonState);
break;
case 1:
Joystick.setButton(1, currentButtonState);
break;
case 2:
Joystick.setButton(2, currentButtonState);
break;
case 4: // RIGHT
if (currentButtonState == 1) {
Joystick.setXAxis(1);
} else {
Joystick.setXAxis(0);
}
break;
case 3: // LEFT
if (currentButtonState == 1) {
Joystick.setXAxis(-1);
} else {
Joystick.setXAxis(0);
}
break;
case 5:
Joystick.setButton(3, currentButtonState);
break;
case 6:
Joystick.setButton(4, currentButtonState);
break;
}
lastButtonState[index] = currentButtonState;
}
}
delay(10);
}