#include <Keypad.h>
char* password = "123"; // change the password here, just pick any 3 numbers
int possition = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 7, 9, 8, 7 };
byte colPins[COLS] = { 6, 5, 4, 3 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int pir = 2;
int led = 12;
int sttate = 0;
int rep = 11;
int alarm = 0;
int ledZ = 13;
void setup(){
pinMode(2,INPUT_PULLUP);
pinMode(13,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
Serial.begin(9600);
LockedPosition(true);
}
void loop(){
char key = keypad.getKey();
if (possition == 0)
{
LockedPosition(true);
}
if (key == '*' || key == '#')
{
possition = 0;
}
if (key == password[possition])
{
possition ++;
}
if (possition == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked){
sttate = digitalRead(pir);
if (sttate == HIGH)
{
alarm = 1;
}
if (alarm == 1 )
{
digitalWrite(led,HIGH);
analogWrite(rep,80);
}
Serial.println(sttate);
}
else {
digitalWrite(led,LOW);
analogWrite(rep,0);
alarm = 0;
LockedPosition(true);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
delay(500);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
delay(500);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
digitalWrite(ledZ,HIGH);
delay(500);
digitalWrite(ledZ,LOW);
}
}
Comments