Joystick and Keypad library help

Hi, I’ve been struggling a while with a dilemma in Code, I set up a switch panel using the keypad and joystick library but for the life of me can’t figure out how to make a certain button HOLD longer than the rest. I’m struggling to figure out the code as i have tried a few different way but to no avail… Using a Arduino pro micro and Leonardo.

#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;

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, 11, 12, 13};
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);



}

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);
break;
case HOLD:
If (i == 8) {
Joystick.setButton(switchpnl.key[i].kchar, 1);
delay(12000);
Joystick.setButton(switchpnl.key[i].kchar, 0);
}
Joystick.setButton(switchpnl.key[i].kchar, 1);
delay(3000);
Joystick.setButton(switchpnl.key[i].kchar, 0);
break;
case RELEASED:
case IDLE:
Joystick.setButton(switchpnl.key[i].kchar, 0);
break;
}
}
}
}
}

By the end of the sketch you will see the case HOLD with an if statement (if “i” = 8 (button 8 on the array) then it should delay the hold for 12 seconds, the normal 3 second delay hold case works fine. Just can’t seem to figure out the code for it i also tried creating a void just for button 8 but also did not work. Any help would be appreciated as sofar none has been able to.

Here are library links: Joystick: https://github.com/MHeironimus/ArduinoJoystickLibrary
Keypad: https://github.com/Chris--A/Keypad

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile: