#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 = Serial.read();
switch (input) {
case '*': //reset password
password.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();
}
}
}
The issue with this code is that i want to be able to enter the # or * key on the keypad itself to reset or evaluate the password, not have to enter it on the serial monitor to do the function.