Hi all,
I have a 9 button panel I made for flight simulator using 9 momentary push buttons wired using the keypad code using 3rows x 3 columns.
I want to know if it’s possible to edit the code and wire up individual LEDS as to when I push one of the push buttons an LED is toggled on and stays on until toggles off again.
I’m not that experienced with coding. All help appreciated thank you.
Using Arduino Pro Micro board.
[code]
#include <Keypad.h>
#include <Joystick.h>
//Potentiometer Setup
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
9, 0, // Button Count, Hat Switch Count
true, true, true, // X, Y, and Z Axis
true, false, false, // Rx, but no Ry or Rz (Rx represents throttle)
false, false, // No rudder or throttle (represented as Rx)
false, false, false); // No accelerator, brake, or steering;
int throttle = 0;
int fuel = 0;
int lastButtonState = 0;
const byte ROWS = 3; //four rows
const byte COLS = 3; //four columns
char buttons[ROWS][COLS] = {
{0, 1, 2},
{3, 4, 5},
{6, 7 ,8},
};
byte rowPins[ROWS] = {4, 5, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 8, 9}; //connect to the column pinouts of the keypad
Keypad throttleButtons = Keypad(makeKeymap(buttons), rowPins, colPins, ROWS, COLS);
void setup(){
Joystick.begin();
}
void loop(){
checkButtons();
throttle = analogRead(A0);
throttle = map(throttle,0,1023,0,255);
Joystick.setRxAxis(throttle);
fuel = analogRead(A1);
fuel = map(fuel,0,1023,0,255);
Joystick.setXAxis(fuel);
delay(30);
}
void checkButtons(void) {
if (throttleButtons.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if (throttleButtons.key[i].stateChanged )
{
switch (throttleButtons.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(throttleButtons.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(throttleButtons.key[i].kchar, 0);
break;
}
}
}
}
}
[/code]