Hi,
I am currently working on a button box project. It all seems to work, but while my code looks fine, the last 3 buttons do not seem to work.
I tested the buttons physically and they are giving signal when pressed.
I have wired the buttons up as you can see in the wiring image.
The code is as following:
#include <Keypad.h>
#include <Joystick.h>
#define NUMBUTTONS 30
#define NUMROWS 5
#define NUMCOLS 6
//define the symbols on the buttons of the keypads
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},
};
byte rowPins[NUMROWS] = {6,5,4,3,2}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,8,9,10,11,12}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 34, 0, false, false, false, false, false, false, false, false, false, false, false);
void setup() {
Joystick.begin();
}
void loop() {
CheckAllButtons();
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( buttbx.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (buttbx.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}
As you can also see on the attached image, the top 2 rows are 6 columns, the bottom 3 are 5 columns.
I am not complaining about the buttons that are not in that place, as they cannot be pressed.
It is the last 3 buttons that do not give any input while they should.
Thank you in advance for any help.
Best regards,
Kristof