Hello everyone! I am Building a Button Box and can't quite figure out where I went wrong! Wiring or code or both! LUL, Below I will share wiring diagram and the code.
I am using a Arduino Micro.
15 push button momentary switches
2 on off toggles switches SPST
1 on off on SPDT
The switch used in the upper left is not a part the circuit with the Micro. It is a separate 12v circuit that only powers 2 LEDs. These are independent of everything else.
So the issue I am having is when I press any momentary switch on the top row they work in widows USB Game Controllers window. However all the rest of the switches repot on the same assigned button.
Not to sure how else to fix this issue. As you can see I am using the Matrix Method to program the buttons. If I need to use a different Arduino I can or what have I missed with the code or buttons.
Code.
#include <Joystick.h>
#include <Key.h>
#include <Keypad.h>
byte inputs[] = {A3, A4, A5, 7, 4, 6, 5, 11, A0, 12};
const int inCount = sizeof(inputs) / sizeof(inputs[0]);
byte outputs[] = {A1, 9, 3, 8, 10};
const int outCount = sizeof(outputs) / sizeof(outputs[0]);
#define NUMBUTTONS 19
#define NUMROWS 5
#define NUMCOLS 10
byte buttons[NUMROWS][NUMCOLS] = {
{A1, 9, 3, 8, 10},
{A3, A4, A5, 7, 4, 6, 5, 11, A0, 12},
};
byte rowPins[NUMROWS] = {A1, 9, 3, 8, 10};
byte colPins[NUMCOLS] = {A3, A4, A5, 7, 4, 6, 5, 11, A0, 12};
Keypad RevButtonBox1 = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 18, 0,
false, false, false, false, false, false,
false, false, false, false, false);
void setup() {
Joystick.begin();
}
void loop() {
CheckAllButtons();
delay(0);
}
void CheckAllButtons(void) {
if (RevButtonBox1.getKeys())
{
for (int i = 0; i < LIST_MAX; i++)
{
if ( RevButtonBox1.key[i].stateChanged )
{
switch (RevButtonBox1.key[i].kstate)
{
case PRESSED:
case HOLD:
Joystick.setButton(RevButtonBox1.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(RevButtonBox1.key[i].kchar, 0);
break;
}
}
}
}
}
Many thanks and any Help would be greatly appreciated!
Rev.