Hi i am trying to figure out why an LED won't light up when a button is pressed using the keypad and joystick library, is there a problem with my code? LED is connected to pin 1 and ground on a pro micro.
#include <Joystick.h>
#include <Keypad.h>
#include <DynamicHID.h>
#define ENABLE_PULLUPS
#define NUMBUTTONS 32
#define NUMROWS 6
#define NUMCOLS 6
int Dial1 = A0;
int Dial2 = A1;
int Dial3 = A2;
int Dial4 = A3;
int LED = 1;
byte buttons[NUMROWS][NUMCOLS] = {
{0, 1, 2, 3, 4, 5},
{6, 7, 8, 9, 10, 11},
{12, 13, 14, 15, 16, 17},
{18, 19, 20, 21, 22, 23},
{24, 25, 26, 27, 28, 29},
{30, 31}
};
byte rowPins[NUMROWS] = {8, 9, 10, 14, 15, 16};
byte colPins[NUMCOLS] = {2, 3, 4, 5, 6, 7};
Keypad switchpnl = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, true, false, false, false, true, true, true, false, false);
void setup() {
Joystick.begin();
Joystick.setZAxisRange(0, 1023);
Joystick.setRudderRange(0, 1023);
Joystick.setThrottleRange(0, 1023);
Joystick.setAcceleratorRange(0, 1023);
pinMode(LED, OUTPUT);
}
void JButtonStates() {
Joystick.setZAxis(analogRead(Dial1));
Joystick.setRudder(analogRead(Dial2));
Joystick.setThrottle(analogRead(Dial3));
Joystick.setAccelerator(analogRead(Dial4));
}
void loop() {
JButtonStates();
delay(10);
CheckAllButtons();
}
void CheckAllButtons(void)
{
if (switchpnl.getKeys())
{
for (int i = 0; i < LIST_MAX; i++)
{
if ( switchpnl.key[i].stateChanged )
{
switch (switchpnl.key[i].kstate)
{
case PRESSED:
Joystick.setButton(switchpnl.key[i].kchar, 1);
if (i == 0){
digitalWrite(LED, HIGH);
}
break;
case HOLD:
Joystick.setButton(switchpnl.key[i].kchar, 1);
delay(2500);
Joystick.setButton(switchpnl.key[i].kchar, 0);
break;
case RELEASED:
case IDLE:
Joystick.setButton(switchpnl.key[i].kchar, 0);
if (i == 0){
digitalWrite(LED, LOW);
}
break;
}
}
}
}
}