#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte ROWS = 4;
const byte COLS = 4;
#define LED1_PIN 26
#define LED2_PIN 27
char Keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 14, 12, 19, 18 };
byte colPins[COLS] = { 5, 4, 2, 15 };
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
char customKey;
int number = 0;
int password = 1379;
void setup() {
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
lcd.init ();
lcd.setBacklight(HIGH);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Input Password");
customKey = customKeypad.getKey();
switch(customKey){
case '0' ... '9':
lcd.setCursor(0,1);
number = number * 10 + (customKey - '0');
lcd.print(number);
break;
case '#':
if(number == password){
lcd.setCursor(0,1);
lcd.print("Access Accepted ");
digitalWrite(LED1_PIN, LOW);
digitalWrite(LED2_PIN, HIGH);
delay(2000);
number = 0;
lcd.clear();
}
else{
lcd.setCursor(0,1);
lcd.print("Invalid Password");
digitalWrite(LED1_PIN, HIGH);
digitalWrite(LED2_PIN, LOW);
delay(2000);
number = 0;
lcd.clear();
}
break;
case '*':
number = 0;
lcd.clear();
break;
}
}