Is there a simpler way to write this?
There are 8 buttons on a joystick im using.
#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4; //four rows
const byte COLS = 2; //three columns
char keys[ROWS][COLS] = {
{'1','2'},
{'3','4'},
{'5','6'},
{'7','8'}
};
byte rowPins[ROWS] = {48, 46 , 44, 42}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {52, 50}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int pb =0;
void setup() {
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
switch (key){
case '1':
lcd.begin(16, 2);
lcd.print("JS Foward");
break;
case '2':
lcd.begin(16, 2);
lcd.print("Trigger Pressed");
break;
case '3':
lcd.begin(16, 2);
lcd.print("JS Right");
break;
case '4':
lcd.begin(16, 2);
lcd.print("Left PB");
break;
case '5':
lcd.begin(16, 2);
lcd.print("JS Back");
break;
case '6':
lcd.begin(16, 2);
lcd.print("Right PB Top");
break;
case '7':
lcd.begin(16, 2);
lcd.print("JS Left");
break;
case '8':
lcd.begin(16, 2);
lcd.print("Right PB Back");
break;
}
}