hello,
I am trying to use and arduino and a keypad to replace my old broken garage door opener keypad. I am going to have a relay trip when the correct code is entered in the keypad. One problem though. Once I type in the code, I HAVE to hit clear, otherwise you can just hit enter and get in. any help?
#include <Password.h>
#include <Keypad.h>
Password password = Password( "1234" );
int state = 1; //automatically sets to locked state
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] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};
// Create the Keypad
int ledpin = 13;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(ledpin, OUTPUT);
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
}
void loop(){
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*': checkPassword(); break;
case '#': password.reset(); break;
default: password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
Serial.println("Success");
digitalWrite(ledpin, HIGH);
delay(500);
digitalWrite(ledpin, LOW);
}else{
Serial.println("Wrong");
digitalWrite(ledpin, LOW);
}
}