#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad Teclado = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
const String password = "1234";
String input_password;
void setup(){
Serial.begin(9600);
pinMode(10, OUTPUT);//led
pinMode(11, OUTPUT);//buzzer
pinMode(12, OUTPUT);//led
input_password.reserve(32);
}
void loop(){
char customKey = Teclado.getKey();
if (customKey){
Serial.println(customKey);
if(customKey == '*') {
input_password = "";
} else if(customKey == '#') {
if(password == input_password) {
Serial.println("Contraseña Correcta :D");
tone(11,440,2000);//PIN, TONO ,DURACION
delay(2000);
tone(11,480,2000);//PIN, TONO ,DURACION
delay(1000);
tone(11,550,2000);//PIN, TONO ,DURACION
delay(500);
digitalWrite(12,HIGH);
delay(500);
digitalWrite(12, LOW);
} else {
Serial.println("Contraseña Incorrecta, intentalo de nuevo");
tone(11,700,1000);//PIN, TONO ,DURACION
delay(500);
digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW);
}
input_password = "";
} else {
input_password += customKey;
}
}
}