#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const byte bar = 4;
const byte kol = 4;
char tbl[bar][kol] = {
{'1', '2', '3', 'A'},
{'3', '4', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'},
};
byte barPin[bar] = { 9, 8, 7, 6 };
byte kolPin[kol] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(tbl), barPin, kolPin, bar, kol);
char customKey;
int num = 0;
int password = 11;
int redPin = 13;
int greenPin = 12;
int cursor=0;
void setup() {
lcd.init ();
lcd.setBacklight(HIGH);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Input Password");
customKey = keypad.getKey();
switch(customKey) {
case '0' ... '9':
lcd.setCursor(cursor, 1);
num = num*10 + (customKey - '0');
lcd.print(customKey);
if (cursor<15) {
cursor++;}
break;
case '#':
if(num == password) {
lcd.setCursor(0,1);
lcd.print("Access Accepted ");
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}else{
lcd.setCursor(0,1);
lcd.print("Invalid Password");
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
break;
case '*':
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
num = 0;
lcd.clear();
break;
}
}