Skip to content

Instantly share code, notes, and snippets.

@nilsonpessim
Created April 3, 2014 14:26
Show Gist options
  • Save nilsonpessim/9955355 to your computer and use it in GitHub Desktop.
Save nilsonpessim/9955355 to your computer and use it in GitHub Desktop.
#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