1#include <Keypad.h>
2
3char* password = "123";
4int possition = 0;
5const byte ROWS = 4;
6const byte COLS = 4;
7char keys[ROWS][COLS] = {
8{'1','2','3','A'},
9{'4','5','6','B'},
10{'7','8','9','C'},
11{'*','0','#','D'}
12};
13
14byte rowPins[ROWS] = { 7, 9, 8, 7 };
15byte colPins[COLS] = { 6, 5, 4, 3 };
16Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
17
18
19
20int pir = 2;
21int led = 12;
22int sttate = 0;
23int rep = 11;
24int alarm = 0;
25int ledZ = 13;
26
27void setup(){
28pinMode(2,INPUT_PULLUP);
29pinMode(13,OUTPUT);
30pinMode(11,OUTPUT);
31pinMode(12,OUTPUT);
32Serial.begin(9600);
33LockedPosition(true);
34}
35
36void loop(){
37char key = keypad.getKey();
38 if (possition == 0)
39 {
40 LockedPosition(true);
41}
42if (key == '*' || key == '#')
43{
44possition = 0;
45 }
46
47if (key == password[possition])
48{
49possition ++;
50}
51if (possition == 3)
52{
53LockedPosition(false);
54}
55delay(100);
56}
57void LockedPosition(int locked)
58{
59if (locked){
60sttate = digitalRead(pir);
61if (sttate == HIGH)
62 {
63 alarm = 1;
64 }
65if (alarm == 1 )
66 {
67 digitalWrite(led,HIGH);
68 analogWrite(rep,80);
69 }
70
71 Serial.println(sttate);
72}
73else {
74 digitalWrite(led,LOW);
75 analogWrite(rep,0);
76 alarm = 0;
77 LockedPosition(true);
78 digitalWrite(ledZ,HIGH);
79 delay(500);
80 digitalWrite(ledZ,LOW);
81 delay(500);
82 digitalWrite(ledZ,HIGH);
83 delay(500);
84 digitalWrite(ledZ,LOW);
85 delay(500);
86 digitalWrite(ledZ,HIGH);
87 delay(500);
88 digitalWrite(ledZ,LOW);
89 digitalWrite(ledZ,HIGH);
90 delay(500);
91 digitalWrite(ledZ,LOW);
92 digitalWrite(ledZ,HIGH);
93 delay(500);
94 digitalWrite(ledZ,LOW);
95 digitalWrite(ledZ,HIGH);
96 delay(500);
97 digitalWrite(ledZ,LOW);
98 digitalWrite(ledZ,HIGH);
99 delay(500);
100 digitalWrite(ledZ,LOW);
101 digitalWrite(ledZ,HIGH);
102 delay(500);
103 digitalWrite(ledZ,LOW);
104 }
105 }