i have here the sample code:
#include <Password.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
Password password = Password( "123456" ); //This is our password
LiquidCrystal lcd(14, 13, 12, 11, 10, 9);
const byte ROWS = 4; // 4 rows
const byte COLS = 3; // 3 columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {8, 7, 6};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
pinMode(15, OUTPUT);
lcd.begin(16, 2);
lcd.print(" Enter Password");
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void loop()
{
lcd.setCursor(0, 1);
keypad.getKey();
}
//check the keypad events
void keypadEvent(KeypadEvent keyPress)
{
switch (keypad.getState())
{
case PRESSED:
lcd.print(keyPress); //print the keypress
switch (keyPress)
{
case '#':
checkPassword();
break;
case '*':
password.reset();
digitalWrite(15, LOW);
lcd.setCursor(0,1);
lcd.print(" ");
break;
default:
password.append(keyPress);
}
}
}
//check the entered password
void checkPassword(){
if (password.evaluate()) //if password is correct
{
lcd.setCursor(0,1);
lcd.print("Correct Password"); //print a message on serial monitor
digitalWrite(15, HIGH); //turn ON an LED
password.reset(); //reset password
}
else
{
lcd.setCursor(0,1);
lcd.print(" Wrong Password"); //if password is wrong
digitalWrite(15, HIGH); //blink an LED
delay(100);
digitalWrite(15, LOW);
delay(100);
digitalWrite(15, HIGH);
delay(100);
digitalWrite(15, LOW);
password.reset(); //reset password
}
}
i'm wondering how to transfer the void keypadEvent function to void setup. I tried to cut and paste but it doesn't work. I'm planning to put something inside the void loop. I'm making an authorization to our thesis project. What i wanna do is to have the authorization in the void setup before it will proceed to the main program that i will put inside the void loop. please help! i'd really appreciate it..A LOT! thanks!!