#include<LiquidCrystal.h>
#include "Keypad.h"
const byte row = 4;
const byte col = 4;
char keys[row][col]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
char pass[] = {'1','5','9','D','C','0'};
char newpass[6];
byte rowpins[] = {22,23,24,25};
byte colpins[] = {26,27,28,29};
int i= 0,f =0,c=0,error =0;
Keypad mykeypad = Keypad(makeKeymap(keys),rowpins,colpins,row,col);
LiquidCrystal lcd(7,6,5,4,3,2);
void print1(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter password ");
lcd.setCursor(0,1);
}
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("* hello there * ");
delay(2000);
print1();
}
void loop() {
char key = mykeypad.getKey();
if(key !=NO_KEY && i<6){
lcd.setCursor(i,1);
lcd.print("*");
newpass[i] = key;
if(newpass[i]== pass[i])
c++;
i++;
}
if (c == 6){
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("correct");
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
i=0;
c=0;
error = 0;
print1();
}
if (c<6 &&i ==6){
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Invalid Password");
delay(1000);
i=0;
c=0;
error++;
if (error == 3){
lcd.print("Invalid Password");
lcd.setCursor(0,1);
lcd.print("u must waite ");
delay(1000);
Serial.println("NNMM");
for (int i=180;i>=0;i--){
lcd.setCursor(13,1);
lcd.print(i);
delay(1000);
}
}
else
print1();
}
}
Comments
Please log in or sign up to comment.