Pages: [1]   Go Down
Author Topic: Password Libary with Keypad  (Read 674 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

im currently doing a password lock project, im having some issues with the code while entering the password, it gives me "invalid password" regardless of the password being right or wrong, anyway here is the code below, any help will be greatly appreciated smiley

Thanks...
Code:
#include <Keypad.h>
#include <Password.h>
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','#'}
 };
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };
 
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


Password password = Password("1234");


#define ledPin  13

void setup(){
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  digitalWrite(ledPin, HIGH);   // sets the LED on
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener
  keypad.setDebounceTime(250);
}
 
void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (eKey){
    case '*': tryPassword(); break;
    case '#': password.reset(); break;
   default:  password.append(eKey);
  }
}

void tryPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){      
 Serial.println("VALID PASSWORD "); //
              password.reset(); //resets password after correct entry
     }else{
Serial.println("INVALID PASSWORD ");
         password.reset(); //resets password after INCORRECT entry
     }
}
Logged

Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm just reading a few lines but maybe it's something in the hardware.

Did you try Serial.print(ekey); for debugging?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the reply,

i have tried doing that aswell, cant seem to figure it out.. do you know if there is a way to have password without using the password libary? if that makes sense?
sorry my programming is not too good.

Thanks smiley
Logged

Pages: [1]   Go Up
Jump to: