Hello,
I've been trying to get my button box to work. I used the code from a youtube tutorial and altered it for my button box but it wont work. Hardware wise I made columns and rows. Rows connected to A5 to A0 and pin 12 and columns connected to pin 10,9,8. I don't get an error in the code but when I try to assign buttons in-game they don't react.
Thanks in advance!
#include <Keypad.h>
#include <Joystick.h>
#define NUMBUTTONS 16
#define NUMROWS 8
#define NUMCOLS 3
byte buttons[NUMROWS][NUMCOLS] = {
{0,1},
{2,3},
{4,5},
{6,7},
{8,9},
{10,11,12},
{13,14},
{15},
};
byte rowPins[NUMROWS] = {19,18,17,16,15,14,12};
byte colPins[NUMCOLS] = {10,9,8};
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 32, 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);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}