Hi fellow Arduino'ers,
i build with my arduino micro an 4x6 Buttonmatrix for a Game.
I can't access the first button (Doesn't match with any Pin setup).
Buttons two to seven are working perfectly. But the the problem appears.
If i press 8 the Controller output is 8 -> 9 -> 10 -> 11 -> 8 -> 9 -> 10 -> 11. If i press any other button it is the same result. The same behavior is for the buttons 14 - 17. The Buttons 12, 13 and 18 are working.
Code is below. Hope anyone can help me. Tried to fix it for many hours and don't catch the error.
#include <Keypad.h>
#include <Joystick.h>
#define NUMBUTTONS 24
#define NUMROWS 4
#define NUMCOLS 6
#define LIST_MAX 24
byte buttons[NUMROWS][NUMCOLS] = {
{1,2,3,4,5,6},
{7,8,9,10,11,12},
{13,14,15,16,17,18},
{19,20,21,22,23,24},
};
byte rowPins[NUMROWS] = {11,10,9,8};
byte colPins[NUMCOLS] = {7,6,5,4,3,2};
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 24, 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++)
{
if ( buttbx.key[i].stateChanged )
{
switch (buttbx.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
delay(1000);
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}