Hello, I wrote code for my 3x4 keypad in which I want to setup a 4 digit password. I was able to get a serial print for the reset, which is working fine but the password.evaluate I believe is not working properly because it always displays you did not guess the correct password.
The library I'm using for the password is Password.H any ideas in how to fix it? I am relatively new with arduino and I have no idea where to start.
#include <Keypad.h>
#include <Password.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 50, 49, 48, 47 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 46, 45, 44 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
//Setup Password
Password password = Password("1234");
void setup()
{
pinMode(ledpin,OUTPUT);
digitalWrite(ledpin, HIGH);
Serial.begin(9600);
Serial.println("Enter the password: ");
}
void loop()
{
char input = kpd.getKey();
switch (input){
case '#': //reset password
password.reset();
Serial.println("\tPassword is reset!");
break;
case '*': //evaluate password
if (password.evaluate()){
Serial.println("\tYou guessed the correct password!");
password.reset();
}else{
Serial.println("\tYou did not guess the correct password!");
password.reset();
}
break;
default: //append any keypress that is not a '*' nor a '#' to the currently guessed password.
Serial.print(input);
password.append(input);
}
}
Any help is appreciated.