-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDTMF.ino
196 lines (182 loc) · 4.3 KB
/
DTMF.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <math.h>
#include <LiquidCrystal.h>
#include <Stepper.h>
LiquidCrystal lcd(8,9,10,11,12,13);
static int current_state = 0,p=0;
String str = "";
String password = "1234";
int i = -1, count = 0, prevcmd = -1;
boolean first = true, open = false, done = false, reset = false;
boolean alreadyOpen = false, alreadyClose = false;
const int stepsPerRevolution = 20;
Stepper myStepper(stepsPerRevolution, 3, 4, 6, 7); // IC - Arduino 2-7, 7-6, 10-4, 15-3
void setup() {
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(2 ,OUTPUT);
lcd.begin(16, 2);
lcd.print("hello, world!");
myStepper.setSpeed(60);
Serial.begin(9600);
}
void loop() {
first:
int b1 = analogRead(A2) >= 150 ? 1 : 0;
int b2 = analogRead(A3) >= 150 ? 1 : 0;
int b3 = analogRead(A4) >= 150 ? 1 : 0;
int b4 = analogRead(A5) >= 150 ? 1 : 0;
int command = b1*8 + b2*4 + b3*2 + b4;
Serial.println();
Serial.println();
Serial.println();
Serial.println();
if(command == 10)
command = 0;
Serial.println(command);
if(command == prevcmd) {
delay(1000);
goto first;
}
prevcmd = command;
str += String(command);
Serial.println(str);
if(reset) {
Serial.println("inside reset");
lcd.clear();
lcd.print("type new");
lcd.setCursor(0, 1);
lcd.print("password...");
if(str.length() == 4) {
password = str;
reset = false;
lcd.clear();
lcd.print("new password");
lcd.setCursor(0, 1);
lcd.print(password);
delay(2000);
str = "";
}
goto first;
}
if(done) {
if(command == 11)
openDoor();
else if(command == 12)
closeDoor();
else if(command == 0) {
lcd.clear();
lcd.print("type new");
lcd.setCursor(0, 1);
lcd.print("password...");
reset = true;
} else {
lcd.clear();
lcd.print("wrong option");
lcd.setCursor(0, 1);
lcd.print("selected");
delay(500);
lcd.clear();
lcd.print("type pswd");
lcd.setCursor(0, 1);
lcd.print("again");
}
done = false;
str = "";
goto first;
}
if((str.length() == 5 && first) || (str.length() == 4 && !first)) {
int i = first? 1: 0;
first = false;
lcd.clear();
if(str.substring(i,i+4) == password){
Serial.println("Correct Password");
lcd.print("Correct pswd");
delay(500);
done = true;
lcd.clear();
lcd.print("CHOOSE *:Open");
lcd.setCursor(0, 1);
lcd.print("#:Close 0:Reset");
count = 0;
//myStepper.step(stepsPerRevolution);
//delay(500);
//open = true;
} else {
Serial.println(str.substring(i, i+4) + " is wrong password!!!");
lcd.print(str.substring(i, i+4) + "wrong pass");
//if(open) {
//myStepper.step(-stepsPerRevolution);
//delay(500);
//}
//open = false;
count++;
}
str = "";
}
if(str.length() >= 100)
str = "";
if(count >= 5) {
wait();
count = 0;
}
delay(1000);
}
void wait() {
Serial.println("You've entered wrong password 5 times!!!");
Serial.println("Try after 30 seconds.....");
lcd.print("Entered wrong pswd 5 times");
int secondsLeft = 30;
while(secondsLeft > 0) {
lcd.clear();
if(secondsLeft&1)
digitalWrite(2 ,HIGH);
else
digitalWrite(2 ,LOW);
lcd.print("Try after ");
lcd.print(secondsLeft);
lcd.print(" sec");
delay(1000);
secondsLeft--;
}
digitalWrite(2 ,LOW);
lcd.clear();
lcd.print("Enter password");
lcd.setCursor(0, 1);
lcd.print("now!!");
lcd.clear();
first = true;
}
void openDoor() {
if(alreadyOpen) {
lcd.clear();
lcd.print("door is");
lcd.setCursor(0, 1);
lcd.print("already opened");
return;
}
myStepper.step(stepsPerRevolution);
lcd.clear();
lcd.print("Opening....");
delay(2000);
lcd.clear();
alreadyOpen = true;
alreadyClose = false;
}
void closeDoor() {
if(alreadyClose) {
lcd.clear();
lcd.print("door is");
lcd.setCursor(0, 1);
lcd.print("already closed");
return;
}
myStepper.step(-stepsPerRevolution);
lcd.clear();
lcd.print("Closing....");
delay(2000);
lcd.clear();
alreadyClose = true;
alreadyOpen = false;
}