#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int row=4;
const int col=4;
char arr[row][col]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
byte rpin[row]={2,3,4,5};
byte cpin[col]={6,7,8,9};
Keypad mykey=Keypad(makeKeymap(arr),rpin,cpin,row,col);
int g=12;
int r=11;
int bu=10;
String pass="1234";
int count=0;
String temp;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.backlight();
lcd.print("Enter password");
delay(2000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
char key=mykey.getKey();
if(key)
{
if(key=='#')
{
if(temp==pass)
{
digitalWrite(g,HIGH);
lcd.setCursor(1,1);
lcd.print("corecct");
delay(2000);
digitalWrite(g,LOW);
lcd.clear();
}
else if(temp!=pass)
{
count++;
digitalWrite(r,HIGH);
tone(bu,300);
delay(2000);
lcd.setCursor(1,1);
lcd.print("incorecct");
digitalWrite(r,LOW);
noTone(bu);
lcd.clear();
}
}
if(key=='C')
{
lcd.clear();
temp="";
}
else
{
temp+=key;
}
}
if(count==3)
{
digitalWrite(r, HIGH);
tone(bu,300);
lcd.print("incorecct");
}
lcd.setCursor(0,0);
lcd.print(temp);
}