#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Password.h>
Password password = Password( "1234" );
LiquidCrystal lcd(12, 11, 5, 4,3 , 2);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {6, 7, 8, 9};
byte colPins[COLS] = {14, 15, 16};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}
void menu(){
lcd.setCursor(1, 0);
lcd.print("1.Ajust 2.Activ");
lcd.setCursor(0, 1);
lcd.print("3.Mem 4.Err");
}
//take care of some special events
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(key);
switch (key){
case '*': checkPassword(); break;
case '#': password.reset(); break;
default: password.append(key);
}
}
}
void checkPassword(){
if (password.evaluate()){
Serial.println("Activad");
//Add code to run if it works
}else{
Serial.println("Clave Errónea");
//add code to run if it did not work
}
}
void loop(){
char key = keypad.getKey();
if (key){
switch (key)
{
case '1':
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Ajustes");
break;
case '2':
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Activ");
break;
case '3':
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Mem");
break;
case '4':
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Err");
case '5':
keypad.getKey();
break;
default:
menu();
}
}
}
Cuando pulso 5 no me deja meter el password.¿Alguien sabe repararlo?
Un saludo, muchas gracias.