#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
byte rowpins[4]={13,12,11,10};
byte columnpins[4]={9,8,7,6};
char key[4][4]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
LiquidCrystal_I2C lcd(0x27,16,2);
Keypad keys=Keypad(makeKeymap(key),rowpins,columnpins,4,4);
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Lets start");
lcd.setCursor(0,1);
lcd.print("press any key");
delay(500);
Serial.begin(9600);
}
void loop() {
char value= keys.getKey();
if(value){
Serial.println(value);
}
if(value=='1' || value=='2' || value=='3' || value=='A'){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LED 1 iS ON");
lcd.setCursor(0,1);
lcd.print("FOR 1,4,3,D");
}
else if(value=='4' || value=='5' || value=='6' || value=='B'){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LED 2 iS ON");
lcd.setCursor(0,1);
lcd.print("FOR 1,4,7,B");
}
else if(value=='7' || value=='8' || value=='9' || value=='C'){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LED 3 iS ON");
lcd.setCursor(0,1);
lcd.print("FOR 1,7,7,C");
}
else if(value=='*' || value=='0' || value=='#' || value=='D'){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LED 4 iS ON");
lcd.setCursor(0,1);
lcd.print("FOR *,4,#,D");
}
}