-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal-atc.ino
280 lines (201 loc) · 4.19 KB
/
final-atc.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
//Mux control pins
int s0 = 3;
int s1 = 4;
int s2 = 5;
int s3 = 6;
#define ledA1 A5
#define ledA2 A4
#define ledA3 A3 //s pins are 3 4 5 6
#define ledB1 10
#define ledB2 11
#define ledB3 12
#define ledC1 7
#define ledC2 8
#define ledC3 9
#define ledD1 A2
#define ledD2 A1
#define ledD3 13
//
//#define ledZ1 A5 //AMBI-SIGNAL
//#define ledZ2 A4
//#define ledZ3 A3
int a1,a2,b1,b2,c1,c2,d1,d2,t,z1,z2,EMV;
//Mux in "SIG" pin
const int SIG_pin = A0;
const int EN = 7;// Enable pin
const int controlPin[4] = {s0,s1,s2,s3};
void setup() {
Serial.begin(9600);
pinMode(ledA1, OUTPUT);
pinMode(ledA2, OUTPUT);
pinMode(ledA3, OUTPUT);
pinMode(ledB1, OUTPUT);
pinMode(ledB2, OUTPUT);
pinMode(ledB3, OUTPUT);
pinMode(ledC1, OUTPUT);
pinMode(ledC2, OUTPUT);
pinMode(ledC3, OUTPUT);
pinMode(ledD1, OUTPUT);
pinMode(ledD2, OUTPUT);
pinMode(ledD3, OUTPUT);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
}
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
// loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
int val = analogRead(SIG_pin);
//return the value
return val;
}
void loop(){
readval();
//if(EMV<800)
//{
// Serial.println("*************************Ambulance detected on lane A******************************");
// greenchannel();
//}
//else
//{
// Serial.println("Ambulance not detected on any lane");
//
//}
if(a2 <500 || b1 <500 || b2 < 500)
{
laneA();
// if(EMV<800)
// {
// greenchannel();
// }
if(c1 < 500 || c2 < 500 || d1 < 500 || d2 < 500)
{
laneB();
}
else if(a2 <500 && b1 <500 && c2 < 500 )
{
laneA();
}
}
else if(c1 < 500 || c2 < 500 || d1 < 500 || d2 < 500)
{
laneB();
// if(EMV<800)
// {
// greenchannel();
// }
if(a2 <500 || b1 <500 || b2 < 500)
{
laneA();
}
}
else if(c1 < 500 && c2 < 500 && d1 < 500 && d2 < 500)
{
laneB();
}
else
{
digitalWrite(ledA3,HIGH);
digitalWrite(ledB3,HIGH);
digitalWrite(ledC3,HIGH);
digitalWrite(ledD3,HIGH);
}
}
void readval()
{
a2 = readMux(1);
d1 = readMux(6);
d2 = readMux(7);
b1 = readMux(4);
b2 = readMux(5);
c1 = readMux(2);
c2 = readMux(3);
z1 = readMux(13);
z2 = readMux(14);
t=analogRead(readMux(10));
EMV=readMux(12);
//delay(100);
for(int i = 0; i < 11; i ++){
Serial.print("Value at channel ");
Serial.print(i);
Serial.print("is : ");
Serial.println(readMux(i));
}
}
void laneA()
{
digitalWrite(ledA3, LOW);
digitalWrite(ledB3,LOW);
digitalWrite(ledA1, HIGH);
digitalWrite(ledB1,HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(10000);
digitalWrite(ledA2, HIGH);
digitalWrite(ledB2, HIGH);
digitalWrite(ledA1, LOW);
digitalWrite(ledB1, LOW);
delay(1000);
digitalWrite(ledA2, LOW);
digitalWrite(ledB2,LOW);
readval();
}
void laneB()
{
digitalWrite(ledC3, LOW);
digitalWrite(ledD3,LOW);
digitalWrite(ledC1, HIGH);
digitalWrite(ledD1,HIGH);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB3, HIGH);
delay(10000);
digitalWrite(ledC2, HIGH);
digitalWrite(ledD2, HIGH);
digitalWrite(ledC1, LOW);
digitalWrite(ledD1, LOW);
delay(1000);
digitalWrite(ledC2, LOW);
digitalWrite(ledD2,LOW);
readval();
}
void greenchannel()
{
digitalWrite(ledA3, LOW);
digitalWrite(ledA1, HIGH);
digitalWrite(ledB3,HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(10000);
digitalWrite(ledA2, HIGH);
digitalWrite(ledA1, LOW);
delay(1000);
digitalWrite(ledA2, LOW);
readval();
}