#include <LiquidCrystal.h>
#include <Keypad.h>
//variables
int cuadro=7;
int fila=0;
char pass[4]={'1','6','2','A'};
char pass1[4]={'5','2','3','4'};
char pass2[4]={'4','3','2','1'};
int buena=0;
int intento=1;
int precionadas=0;
const byte filas=4;
const byte cols=4;
char llaves[filas][cols]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte filapins[filas]={3,2,1,0};
byte colpins[cols]={7,6,5,4};
Keypad teclado=Keypad(makeKeymap(llaves),filapins,colpins,filas,cols);
void setup()
{
DDRC= 0B00000001;
lcd.begin(20, 3);
lcd.setCursor(0,0);
lcd.print("Digite su clave");
lcd.setCursor(0,1);
lcd.print("D = tecla enter");
lcd.setCursor(0,2);
lcd.print("C = tecla Borrar");
delay(1000);
for(int pos=0;pos<10;pos++){
lcd.scrollDisplayLeft();
delay(100);
}
for(int pos=0;pos<23;pos++){
lcd.scrollDisplayRight();
delay(100);
}
for(int pos=0;pos<11;pos++){
lcd.scrollDisplayLeft();
delay(100);
}
delay(1000);
lcd.clear();
}
void loop()
{
int conteo=10;
lcd.setCursor(0,0);
lcd.print("clave: ");
char tecla=teclado.getKey();
lcd.display();
if(tecla){
precionadas++;
lcd.setCursor(cuadro,0);
if(precionadas<=4){lcd.print("*");}
if(precionadas<=4 and cuadro==7 and (pass[0]==tecla or pass1[0]==tecla or pass2[0]==tecla) ){
buena++;
}
if(precionadas<=4 and cuadro==8 and buena>0 and (pass[1]==tecla or pass1[1]==tecla or pass2[1]==tecla)){
buena++;
}
if(precionadas<=4 and cuadro==9 and buena>1 and (pass[2]==tecla or pass1[2]==tecla or pass2[2]==tecla)){
buena++;
}
if(precionadas<=4 and cuadro==10 and buena>2 and (pass[3]==tecla or pass1[3]==tecla or pass2[3]==tecla)){
buena++;
}
cuadro++;
}
if(tecla=='C'){
precionadas=0;
lcd.clear();
lcd.setCursor(0,1);
cuadro=7;
buena=0;
}
if(tecla=='D'){
precionadas=0;
if(buena==4){
lcd.setCursor(0,1);
lcd.print("Puede pasar");
PORTC= 1<<0;
delay(2000);
PORTC= 0<<0;
lcd.clear();
cuadro=7;
buena=0;}
else{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Error");
intento++;
delay(1000);
lcd.setCursor(0,0);
lcd.print("Intento#");
lcd.setCursor(9,0);
lcd.print(intento);
delay(1000);
lcd.clear();
cuadro=7;
buena=0;
}
if(intento>3){
while(conteo!=0){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Sistema");
lcd.setCursor(0,1);
lcd.print("Bloqueado");
lcd.setCursor(12,1);
lcd.print(conteo);
delay(1000);
conteo--;
}
intento=0;
lcd.clear();
}
}
}