/*Write a program using LCD, LEDs, Buzzer
and keypad to simulate a password based
security lock system. User enters 4-digit
password and if the password is correct buzzer
and Green LED is put on. But if the password
is incorrect Red LED is put on. After three
incorrect attempts Red LED along with buzzer
blinks continuously*/
#include<LiquidCrystal.h>
#include <Keypad.h>
int rs=12;
int en=11;
int d4=A0;
int d5=A1;
int d6=A2;
int d7=A3;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int led=13;
int buzzer=10;
const byte rows=4;
const byte cols=4;
char Keys[rows][cols]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','&'}
};
/*r1=d8,r2=d7,r3=d6,r4=d5
c1=d4,c2=d3,c3=d2,c4=d1*/
byte rPins[rows]={8,7,6,5};
byte cPins[cols]={4,3,2,1};
Keypad customKeypad=Keypad(makeKeymap(Keys),rPins,cPins,rows,cols);
void setup() {
lcd.begin(16,2);
lcd.print("hello google!");
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("system ready!");
pinMode(10, OUTPUT);
}
void loop() {
lcd.setCursor(0,1);
char key=customKeypad.getKey();
if(key!=NO_KEY){
Serial.print(" pressed key!");
Serial.println(key);
lcd.print(key);
tone(10,100);
digitalWrite(13, HIGH);
delay(100);
noTone(10);
digitalWrite(13, LOW);
delay(100);
}
// put your main code here, to run repeatedly:
}