Very confused with my code, doesnt seem to work..
I want a password to be able to be entered on a keypad, then the hash key is pressed (on the keypad) and a green led is light up, when the password is wrong, a red led is sent off.
Nothing about this code is working.
[code/]
#include <Password.h>
#include <Keypad.h>
const byte rows = 4; //four rows
const byte cols = 3; //three columns
Password password = Password ("8776");
char keys[rows][cols] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte currentLength = 0 ;
byte rowPins[rows] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[cols] = {6, 7, 8}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
#define REDLedPin 12
#define GREENLedPin 11
void setup()
{
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(12, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(11, LOW);
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if (key);
Serial.print(key);
if (Serial.available()) {
char input = kpd.getKey();
switch (key) {
case '*': //reset password
password.reset();
Serial.print("RESET");
currentLength = 0;
break;
case '#': //evaluate password
if (password.evaluate()) {
digitalWrite(11, HIGH);
delay(2000);
digitalWrite(11, LOW);
Serial.print("Correct");
} else {
password.reset();
}
Serial.print("Incorrect");
digitalWrite(12, HIGH);
delay(2000);
digitalWrite(12, LOW);
char key = kpd.getKey();
}
}
}