Im working on a new button box for a flight sim. Im using an arduino leonardo and a 4x4 matrix. I want to set it up as a joystick instead of a keypad.
Code compiles fine, uploads fine, it shows up in my device manager as "Arduino Leonardo" with the joystick icon. But when I open up the properties, it shows only 12 inputs (should be 16), and none of the inputs light up when any button is pressed.
Here's the code:
#include <Joystick.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char Keys [ROWS][COLS] = {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11},
{12,13,14,15},
};
byte rowPins[ROWS] = {8,9,10,11};
byte colPins[COLS] = {2,3,4,5};
char customKey = 0;
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
Joystick_ Buttons(0x03,0x05,12,false,false,false,false,false,false,false,false,false,false,false);
void setup(){
Serial.begin(9600);
Buttons.begin();
}
void loop(){
customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
if(customKey == '0'){
Buttons.pressButton(0);
delay(100);
Buttons.releaseButton(0);
}
if(customKey == '1'){
Buttons.pressButton(1);
delay(100);
Buttons.releaseButton(1);
}
if(customKey == '2'){
Buttons.pressButton(2);
delay(100);
Buttons.releaseButton(2);
}
if(customKey == '3'){
Buttons.pressButton(3);
delay(100);
Buttons.releaseButton(3);
}
if(customKey == '4'){
Buttons.pressButton(4);
delay(100);
Buttons.releaseButton(4);
}
if(customKey == '5'){
Buttons.pressButton(5);
delay(100);
Buttons.releaseButton(5);
}
if(customKey == '6'){
Buttons.pressButton(6);
delay(100);
Buttons.releaseButton(6);
}
if(customKey == '7'){
Buttons.pressButton(7);
delay(100);
Buttons.releaseButton(7);
}
if(customKey == '8'){
Buttons.pressButton(8);
delay(100);
Buttons.releaseButton(8);
}
if(customKey == '9'){
Buttons.pressButton(9);
delay(100);
Buttons.releaseButton(9);
}
if(customKey == '10'){
Buttons.pressButton(10);
delay(100);
Buttons.releaseButton(10);
}
if(customKey == '11'){
Buttons.pressButton(11);
delay(100);
Buttons.releaseButton(11);
}
if(customKey == '12'){
Buttons.pressButton(12);
delay(100);
Buttons.releaseButton(12);
}
if(customKey == '13'){
Buttons.pressButton(13);
delay(100);
Buttons.releaseButton(14);
}
if(customKey == '14'){
Buttons.pressButton(14);
delay(100);
Buttons.releaseButton(14);
}
if(customKey == '15'){
Buttons.pressButton(15);
delay(100);
Buttons.releaseButton(15);
}
}
}
Any help/feedback would be great! Thanks!
