I have been working on a button box so that i can play games with some cool controls
I have taken a lot of inspiration from this MAKE THIS BUTTON BOX | 32 FUNCTION w ENCODERS - YouTube
i am only using switches and buttons (now encoders)
i have managed to get a 6 button matrix working(2 rows 3 columns) using the joystick library and the keypad library. I have tested the 6 button code on the the 5*5 grid by only using 2 rows and 3 columns and that also worked meaning it is more than likely a problem with the code rather than anything else.
for some reason when i up the number of buttons and rows and test it the entire row responds for a single button or switch
all i did was copied the code form the 6 button matrix to the 25 button matrix and changed the values for the number of rows buttons and pins
pasted is the 6 button code, attached is the 25 button code that is not working
#include <Joystick.h>
#include <Keypad.h>
const byte rows = 2;
const byte cols = 3;
#define NUMBUTTONS 6
#define NUMROWS 2
#define NUMCOLS 3
byte keys[NUMROWS][NUMCOLS] = {
{0, 1, 2},
{3, 4, 5}
};
char key;
byte rowPins[rows] = {5, 6};
byte colPins[cols] = {7, 8, 9};
Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, 2, 3);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 6, 0,
false, false, false, false, false, false,
false, false, false, false, false);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Joystick.begin();
}
void loop() {
if (myKeypad.getKeys())
{
for (int i = 0; i < NUMBUTTONS; i++)
{
if ( myKeypad.key[i].stateChanged )
{
switch (myKeypad.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(myKeypad.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(myKeypad.key[i].kchar, 0);
break;
}
}
}
}
}
25 button code
#include <Joystick.h>
#include <Keypad.h>
const byte rows = 5;
const byte cols = 5;
#define NUMBUTTONS 25
#define NUMROWS 5
#define NUMCOLS 5
byte keys[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}
};
byte rowPins[rows] = {5, 6, 7, 8, 9};
byte colPins[cols] = {A0, 15, 14, 16, 10};
Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, 5, 5);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 25, 0,
false, false, false, false, false, false,
false, false, false, false, false);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Joystick.begin();
}
void loop() {
if (myKeypad.getKeys())
{
for (int i = 0; i < NUMBUTTONS; i++)
{
if ( myKeypad.key[i].stateChanged )
{
switch (myKeypad.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(myKeypad.key[i].kchar, 1);
Joystick.sendState();
break;
case RELEASED:
case IDLE:
Joystick.setButton(myKeypad.key[i].kchar, 0);
Joystick.sendState();
break;
}
}
}
}
}
3.2_25_buttons_dose_not_work.ino (1.34 KB)