(i would if i'm in situation alarm on in alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)
this is the code
#include <Password.h>
#include <Keypad.h>
Password password = Password( "7777" );
const byte ROWS = 4;
const byte COLS = 4;
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte rowPins[ROWS] = { 8, 7, 6,5 };
byte colPins[COLS] = { 12, 11, 10,9 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledPin 13
#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 3, 2, 1, 0,14);
const int buttonPin_DOOR =15; // the number of the pushbutton pin
const int buttonPin_WINDOWS=16;
const int buttonPin_ON_IN=17;
const int buttonPin_ON_OUT=19;
const int ledPin_ALARM= 18;
int ON_IN=0;
int ON_OUT=0;
int buttonState_DOOR = 1; // variable for reading the pushbutton status
int buttonState_WINDOWS= 1;
int buttonState_ON_IN= 0;
int buttonState_ON_OUT= 0;
void setup(){
pinMode(buttonPin_DOOR, INPUT);
pinMode(buttonPin_WINDOWS,INPUT);
pinMode(buttonPin_ON_IN,INPUT);
pinMode(buttonPin_ON_OUT ,INPUT);
pinMode(ledPin_ALARM , OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(0,0);
digitalWrite(ledPin, LOW);
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(250);
}
void loop(){
buttonState_DOOR = digitalRead(buttonPin_DOOR);
buttonState_WINDOWS = digitalRead(buttonPin_WINDOWS);
buttonState_ON_IN= digitalRead(buttonPin_ON_IN);
buttonState_ON_OUT= digitalRead(buttonPin_ON_OUT);
if (buttonState_ON_IN == HIGH &&buttonState_WINDOWS == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN WINDOWS ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (buttonState_ON_IN == HIGH &&buttonState_DOOR == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN DOOR ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (buttonState_ON_IN == HIGH &&buttonState_WINDOWS == LOW && buttonState_DOOR == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN WINDOWS AND ");
lcd.setCursor(0,1);
lcd.print("OPEN DOOR ");
}
if (buttonState_ON_IN == HIGH &&buttonState_DOOR == HIGH &&buttonState_WINDOWS == HIGH) {
lcd.setCursor(0,0);
lcd.print("ALARM ON ");
lcd.setCursor(0,1);
lcd.print("ALARM ");
(ON_IN = HIGH);
}
if (ON_IN == HIGH &&buttonState_DOOR == LOW){
digitalWrite(ledPin_ALARM,HIGH);
lcd.setCursor(0,0);
lcd.print("ALARM ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (ON_IN == HIGH && buttonState_WINDOWS == LOW){
digitalWrite(ledPin_ALARM,HIGH);
lcd.setCursor(0,0);
lcd.print("ALARM ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (buttonState_ON_OUT == HIGH &&buttonState_WINDOWS == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN WINDOWS ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (buttonState_ON_OUT == HIGH &&buttonState_DOOR == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN DOOR ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (buttonState_ON_OUT == HIGH &&buttonState_WINDOWS == LOW && buttonState_DOOR == LOW) {
lcd.setCursor(0,0);
lcd.print("OPEN WINDOWS AND ");
lcd.setCursor(0,1);
lcd.print("OPEN DOOR ");
}
if (buttonState_ON_OUT == HIGH &&buttonState_DOOR == HIGH &&buttonState_WINDOWS == HIGH) {
lcd.setCursor(0,0);
lcd.print("ALARM ON ");
lcd.setCursor(0,1);
lcd.print("ALARM ");
(ON_OUT = HIGH);
}
if (ON_OUT == HIGH &&buttonState_DOOR == LOW){
(i would if i'm in situation alarm on in alarm out situation
if the door open i don't press the correct password the alarm begin
after alarm begin if i press the correct password i'll go in situation alarm off)
digitalWrite(ledPin_ALARM,HIGH);
lcd.setCursor(0,0);
lcd.print("ALARM ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (ON_OUT == HIGH && buttonState_WINDOWS == LOW){
digitalWrite(ledPin_ALARM,HIGH);
lcd.setCursor(0,0);
lcd.print("ALARM ");
lcd.setCursor(0,1);
lcd.print(" ");
}
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
switch (eKey){
case '#': guessPassword(); break;
default:
password.append(eKey);
}
}
}
void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin_ALARM,LOW);
(ON_IN = LOW);
(ON_OUT = LOW);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("CORRECT PASSWORD ");
delay(1000);
lcd.setCursor(0,0);
lcd.print("ALARM ");
lcd.setCursor(0,1);
lcd.print("OFF ");
password.reset();
}else{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("WRONG PASSWORD ");
password.reset();
}
}
Moderator edit: Code put into code box. AWOL