Last active
June 6, 2017 14:46
-
-
Save giltesa/ca833e8406502dde321803dfa2d47c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keypad.h> | |
#define COUNT(x) sizeof(x)/sizeof(*x) | |
HardwareSerial &pc = Serial; | |
class User | |
{ | |
public: | |
String name; | |
String pass; | |
User( String name, String pass ) | |
{ | |
this->name = name; | |
this->pass = pass; | |
} | |
}; | |
User users[] = { | |
User("Paco", "123A"), | |
User("Carmen", "456B") | |
}; | |
const byte pLED = 13; | |
const byte pROWS[] = { 46, 48, 50, 52 }; | |
const byte pCOLS[] = { 47, 49, 51, 53 }; | |
const char KEYS[COUNT(pROWS)][COUNT(pCOLS)] = { | |
{'1','2','3','A'}, | |
{'4','5','6','B'}, | |
{'7','8','9','C'}, | |
{'*','0','#','D'} | |
}; | |
Keypad keypad = Keypad( makeKeymap(KEYS), pROWS, pCOLS, COUNT(pROWS), COUNT(pCOLS) ); | |
String password = ""; | |
void setup() | |
{ | |
pinMode(pLED, OUTPUT); | |
pc.begin(9600); | |
while(!pc); | |
pc.println(F("------------------ PROGRAMA INICIADO ------------------")); | |
pc.println(F("-- INTRODUZCA SU CLAVE Y CONFIRME CON #, BORRE CON * --")); | |
pc.println(F("-------------------------------------------------------")); | |
pc.println(); | |
} | |
void loop() | |
{ | |
char key = keypad.getKey(); | |
if( key > 0 ) | |
{ | |
if( key != '*' && key != '#' ) | |
{ | |
password += key; | |
} | |
else if( key == '*' ) | |
{ | |
pc.println(F("Clave cancelada")); | |
password = ""; | |
} | |
else if( key == '#' ) | |
{ | |
boolean found = false; | |
byte index; | |
for( index=0 ; index < COUNT(users) && !found ; index++){ | |
found = users[index].pass.equalsIgnoreCase(password); | |
} | |
password = ""; | |
if( !found ) | |
pc.println(F("-> CREDENCIALES INCORRECTOS!\n")); | |
else | |
{ | |
pc.print(F("-> BIENVENIDO ")); | |
pc.print(users[index].name); | |
pc.println("!\n"); | |
for( int i=0 ; i < 3 ; i++) | |
{ | |
digitalWrite(pLED, HIGH); | |
delay(500); | |
digitalWrite(pLED, LOW); | |
delay(200); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment