Hi there again!
Thnx for your reply, but tell you the truth, I am giving UP =(
Below is my script, please if anyone can tell me, what am I doing wrong? I just want to enter a password, after enetering it, the reed switch goes "on", so whenever I open a door, windows, etc, the "alarm" goes on. All it does, is let's me to enter my password, and reads only once my reed switch. If I add this to void loop (), everything works great, but then my keyboard and LCD want work as I want it to.... Hope you can understand me (sorry 4 my english - Poland ;))
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Password.h>
Password password = Password ("1234");
LiquidCrystal_I2C lcd(0x21,16,2); //PCF8574
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2,3,4,5}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
//Serial.begin (9600);
lcd.init ();
lcd.backlight ();
lcd.print ("ENTER PIN");
lcd.setCursor (0,1);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
pinMode(13, OUTPUT); //led
pinMode(12, INPUT); //reed switch for DOOR / WINDOW
digitalWrite(12, HIGH); //reed switch for DOOR / WINDOW
pinMode(11,OUTPUT); //buzzer
}
void loop(){
char key = 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(13, 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 PIN"); //print a message on LCD
digitalWrite(13, HIGH); //turn ON an LED
// HERE BELOW I HAVA A PROBLEM - ONLY WORKS ONCE, AND ONLY CHECKS PIN 12 ONCE - what am I doing wrong?
int states;
states = digitalRead(12);
digitalWrite(13, states); //LIGHT LED ON IF WINDOWS OPEN
digitalWrite(11, states); //TURN BUZZER ON, IF WINDOWS OPEN
password.reset(); //reset password
}
else
{
lcd.setCursor(0,1);
lcd.print(" WRONG PIN"); //if password is wrong
digitalWrite(13, HIGH); //blink an LED
delay(100);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
password.reset(); //reset password
}
}