Created
April 3, 2014 14:26
-
-
Save nilsonpessim/9955355 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> | |
char* senha = "159D"; | |
int position = 0; | |
const byte LINHAS = 4; | |
const byte COLUNAS = 4; | |
char teclas[LINHAS][COLUNAS] = { | |
{'1','2','3','A'}, | |
{'4','5','6','B'}, | |
{'7','8','9','C'}, | |
{'*','0','#','D'} | |
}; | |
byte pinoLinha[LINHAS] = {9,8,7,6}; | |
byte pinoColuna[COLUNAS] = {5,4,3,2}; | |
Keypad keypad = Keypad(makeKeymap(teclas), pinoLinha, pinoColuna, LINHAS, COLUNAS); | |
int redPin = 10; | |
int greenPin = 11; | |
void setup(){ | |
pinMode(redPin, OUTPUT); | |
pinMode(greenPin, OUTPUT); | |
fechadoOk(true); | |
} | |
void loop(){ | |
char key = keypad.getKey(); | |
if (key == '*' || key == '#'){ | |
position = 0; | |
fechadoOk(true); | |
} | |
if (key == senha[position]){ | |
position ++; | |
} | |
if (position == 4){ | |
fechadoOk(false); | |
} | |
delay(100); | |
} | |
void fechadoOk(int fechado){ | |
if (fechado){ | |
digitalWrite(redPin, HIGH); | |
digitalWrite(greenPin, LOW); | |
} | |
else{ | |
digitalWrite(redPin, LOW); | |
digitalWrite(greenPin, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment