-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_tashu.ino
313 lines (282 loc) · 6.63 KB
/
2_tashu.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include<LiquidCrystal.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
LiquidCrystal lcd(11,10,9,8,7,6);
SoftwareSerial mySerial(2, 3);
#define sw1 A0
#define sw2 A1
#define sw3 A2
#define sw4 17
#define sw5 18
Adafruit_Fingerprint finger=Adafruit_Fingerprint(&mySerial);
int id =0;
int vote1=0;
int vote2=0;
int vote3=0;
int vote4=0;
/**int fingerinput()
{
lcd.clear();
lcd.setCursor(0, 0);
delay(1000);
lcd.print("Please place your");
lcd.setCursor(0,1);
lcd.print("finger");
id = getFingerprintIDez();
return id;
}**/
void setup()
{
pinMode(sw1, INPUT); //setting all the buttons to receive input
pinMode(sw2,INPUT);
pinMode(sw3,INPUT);
pinMode(sw4,INPUT);
pinMode(sw5,INPUT);
pinMode(13,OUTPUT); //probably to control the lcd
pinMode(12,OUTPUT); //led output
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\nAdafruit finger detect test");
finger.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{
Serial.println("Did not find fingerprint sensor :(");
while (1)
{
delay(1);
}
}
finger.getTemplateCount();
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
Serial.println("Waiting for valid finger...");
lcd.begin(16, 2);
lcd.setCursor(0,0);
//delay(3000);
lcd.print(" VOTING MACHINE ");
lcd.setCursor(0,1);
lcd.print(" LCD DISPLAY");
delay(3000);
digitalWrite(sw1, HIGH); //ensuring all buttons are initialised to high state
digitalWrite(sw2, HIGH);
digitalWrite(sw3, HIGH);
digitalWrite(sw4, HIGH);
digitalWrite(sw5, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" A");
lcd.setCursor(4,0);
lcd.print(" B");
lcd.setCursor(8,0);
lcd.print(" C");
lcd.setCursor(12,0);
lcd.print(" D");
}
void loop()
{
id = getFingerprintIDez();
lcd.clear();
if(id>0)
{
Serial.println("\nreached vote");
lcd.setCursor(0,0);
lcd.print(" A");
lcd.setCursor(1,1);
lcd.print(vote1);
lcd.setCursor(4,0);
lcd.print(" B");
lcd.setCursor(5,1);
lcd.print(vote2);
lcd.setCursor(8,0);
lcd.print(" C");
lcd.setCursor(9,1);
lcd.print(vote3);
lcd.setCursor(12,0);
lcd.print(" D");
lcd.setCursor(13,1);
lcd.print(vote4);
do{
if(digitalRead(sw1)==0)
{
digitalWrite(12,HIGH);
vote1++;
while(digitalRead(sw1)==0); //while loop w no body, stops execution of further statements until button is released
digitalWrite(12,LOW);
delay(1000);
}
else if(digitalRead(sw2)==0)
{
vote2++;
digitalWrite(12,HIGH);
while(digitalRead(sw2)==0);
digitalWrite(12,LOW);
delay(1000);
}
else if(digitalRead(sw3)==0)
{
digitalWrite(12,HIGH);
vote3++;
while(digitalRead(sw3)==0);
digitalWrite(12,LOW);
delay(1000);
}
else if(digitalRead(sw4)==0)
{
digitalWrite(12,HIGH);
vote4++;
while(digitalRead(sw4)==0);
digitalWrite(12,LOW);
delay(1000 );
}
Serial.println("\nreached vote end");
int v = vote1+vote2+vote3+vote4;
Serial.print(v);
lcd.clear();
}
if(digitalRead(sw5)==0)
{
digitalWrite(13,HIGH); //different output?
int vote=vote1+vote2+vote3+vote4;
if(vote)
{
if((vote1 > vote2 && vote1 > vote3 && vote1 > vote4))
{
lcd.clear();
lcd.print("A Wins");
delay(5000);
lcd.clear();
}
else if((vote2 > vote1 && vote2 > vote3 && vote2 > vote4))
{
lcd.clear();
lcd.print("B Wins");
delay(5000);
lcd.clear();
}
else if((vote3 > vote1 && vote3 > vote2 && vote3 > vote4))
{
lcd.clear();
lcd.print("C Wins");
delay(5000);
lcd.clear();
}
else if(vote4 > vote1 && vote4 > vote2 && vote4 > vote3)
{
lcd.setCursor(0,0);
lcd.clear();
lcd.print("D Wins");
delay(5000);
lcd.clear();
}
else
{
lcd.clear();
lcd.print(" Tie Up Or ");
lcd.setCursor(0,1);
lcd.print(" No Result ");
delay(5000);
lcd.clear();
}
}
else
{
lcd.clear();
lcd.print("No Voting….");
delay(5000);
lcd.clear();
}
vote1=0;vote2=0;vote3=0;vote4=0,vote=0;
lcd.clear();
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
}
}while(vote_taken==0)
}
/**uint8_t getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK)
{
Serial.println("Found a print match!");
}
else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return p;
}
else if (p == FINGERPRINT_NOTFOUND)
{
Serial.println("Did not find a match");
return p;
}
else
{
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}**/
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez()
{
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
//lcd.clear();
return finger.fingerID;
}