-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock.ino
163 lines (139 loc) · 3.98 KB
/
lock.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
int m11=7;
int m12=9;
int D0=0;
int D1=0;
int D2=0;
int D3=0;
int m[4];
int n[4];
int p[4];
// Already setted Correct Password for unlock
int password[4][4]={{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0}};
/////////////
//// Array for Receiving entered passwords by user
int input[4][4];
//////////////
int c[4];
int u[4]={1,0,0,1};
bool led = false;
void setup() {
// put your setup code here, to run once:
pinMode(3,INPUT);//dtmf pin
pinMode(4,INPUT);//dtmf pin
pinMode(5,INPUT); //dtmf pin
pinMode(6,INPUT); //dtmf pin
pinMode(7,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13, OUTPUT);//bluetooth*/
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
label : // catches the thrown of code
int count=0;
int i=0,j=0,k=0;
D0=digitalRead(3);
D1=digitalRead(4);
D2=digitalRead(5);
D3=digitalRead(6);
Serial.print(D3);
Serial.print("\t");
Serial.print(D2);
Serial.print("\t");
Serial.print(D1);
Serial.print("\t");
Serial.print(D0);
Serial.print("\n");
if(D3==1 && D2==0 && D1==1 && D0==1)
{
while(1)
{ Serial.println("******in while loop******");
// delay(10000);
// Reading inputs of key pressed through DTMF pins
D0=digitalRead(3);
D1=digitalRead(4);
D2=digitalRead(5);
D3=digitalRead(6);
if(D3==1 && D2==0 && D1==1 && D0==1) ///****
{
}
else{
if(D3==1 && D2==1 && D1==0 && D0==0) //#####
{ // comparision;
if(k<4)
{
for(k=0; k<4; k++)
{ Serial.println("******locked******");
if(password[k][0]==input[k][3] && password[k][1]==input[k][2] && password[k][2]==input[k][1] && password[k][3]==input[k][0])
{count++;} /////// Comparing entered and already setted password
} // comparision for ends
Serial.println("count==== ");
Serial.println(count);
if(count==4)
{ led= !led;
if(led==true)
{
digitalWrite(7,HIGH);
digitalWrite(9,LOW);
Serial.println("locked");
delay(550);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
goto label; }
else if(led==false)
{goto label;}
} // count if ends
} // k<4 if ends
else if(u[0]==c[3] && u[1]==c[2] && u[2]==c[1] && u[3]==c[0])
{
led= !led;
digitalWrite(7,LOW);
digitalWrite(9,HIGH);
Serial.println("locked");
delay(550);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
goto label; }
else
{goto label;
}
} // ### if condition ends
else{
m[0]=D0;
m[1]=D1;
m[2]=D2;
m[3]=D3;
// delay(5000); }
if(i<1)
{
p[0]=D0;
p[1]=D1;
p[2]=D2;
p[3]=D3;
c[0]=D0;
c[1]=D1;
c[2]=D2;
c[3]=D3;
//// Setting entered password
input[j][0]=p[0];
input[j][1]=p[1];
input[j][2]=p[2];
input[j][3]=p[3];
//////////////////////////////////////
j++;
i++;
} // if i<1 condition ends
if(m[3]==p[3] && m[2]==p[2] && m[1]==p[1] && m[0]==p[0])
{ }
else
{i=0;} // upgrading of i ends
} // ### else ends
} /// *** else ends
} // while loop
} // if ****
} // void loop