-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcecode
208 lines (175 loc) · 4.87 KB
/
sourcecode
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
//include the RFID libs
#include <SPI.h>
#include <MFRC522.h>
//include the LCD lib
#include <LiquidCrystal.h>
//declear the reset and SDA pins of RFID
#define SS_PIN 10
#define RST_PIN 9
// Create MFRC522 instance.
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
//declear what LCD pins u are sending data
LiquidCrystal lcd(3, 2, 6, 4, 7, 5);
String pass1 = "CHIBUEZE";
String acct1 = "6A 2D 67 07";
String pass2 = "SMART";
String acct2 = "77 1F 73 63";
int balance1 = 1000;
int balance2 = 1000;
int rate = 200;
void setup()
{
Serial.begin(9600);
// Initiate SPI bus
SPI.begin();
// Initiate MFRC522
mfrc522.PCD_Init();
//begin the LCD
lcd.begin(16, 4);
//state your actuator pins
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
//display a welcome note
lcd.setCursor(0, 0);
lcd.print("WELCOME CHIBUEZE ");
delay(4000);
lcd.setCursor(0, 0);
lcd.print(" BUS TICKET ");
lcd.setCursor(0, 1);
lcd.print(" PAYMENT SYSTEM ");
delay(2000);
lcd.clear();
//mfrc522.PCD_Init(); // Init MFRC522
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
}
void unregisted(){
tone(A0, 1000);
delay(500);
noTone(A0);
delay(500);
tone(A0, 1000);
delay(500);
noTone(A0);
delay(500);
tone(A0, 1000);
delay(500);
noTone(A0);
delay(500);
lcd.setCursor(0, 0);
lcd.print(" UNREGISTERED ");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("PLS GET A VALID CARD");
for (int positionCounter = 0; positionCounter < 43; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}
//lcd.clear();
}
void loop() {
//turn off the actuators
digitalWrite(A0, LOW);
analogWrite(A1, 0);
analogWrite(A2, 0);
lcd.setCursor(0, 0);
lcd.print("Bus Fare is #");
lcd.println(rate);
lcd.println(" ");
lcd.setCursor(0, 1);
lcd.print(" Swipe To Pay ");
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
//this is where u put the UID of the card that you want to give access
if (content.substring(1) == "6A 2D 67 07") {
analogWrite(A2, 255);
delay(250);
analogWrite(A2, 0);
delay(250);
analogWrite(A2, 255);
if (balance1 >= rate){
balance1 -= rate;
lcd.setCursor(0, 0);
lcd.print(" Hi CHIBUEZE ");
lcd.setCursor(0, 1);
lcd.print("___Payment O.K___ ");
}
else{
lcd.setCursor(0, 0);
lcd.print(" Sorry CHIBUEZE ");
lcd.setCursor(0, 1);
lcd.print("Insuficient Fund");
}
delay(4000);
lcd.setCursor(0, 1);
lcd.print("_Balance is #");
lcd.println(balance1);
lcd.println(". .");
delay(4000);
return;
}
if (content.substring(1) == "77 1F 73 63") {
analogWrite(A2, 255);
delay(250);
analogWrite(A2, 0);
delay(250);
analogWrite(A2, 255);
if (balance2 >= rate){
balance2 -= rate;
lcd.setCursor(0, 0);
lcd.print(" Hi SMART ");
lcd.setCursor(0, 1);
lcd.print("___Payment O.K___ ");
}
else{
lcd.setCursor(0, 0);
lcd.print(" Sorry SMART ");
lcd.setCursor(0, 1);
lcd.print("Insuficient Fund");
}
delay(4000);
lcd.setCursor(0, 1);
lcd.print("_Balance is #");
lcd.println(balance2);
lcd.println(". .");
delay(4000);
return;
}
else{
lcd.clear();
analogWrite(A1, 255);
delay(250);
analogWrite(A1, 0);
delay(250);
analogWrite(A1, 255);
unregisted();
}
lcd.clear();
}