-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino IDE Code.txt
185 lines (164 loc) · 4.03 KB
/
Arduino IDE Code.txt
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
#define ledA1 2
#define ledA2 3
#define ledA3 4
#define ledB1 5
#define ledB2 6
#define ledB3 7
#define ledC1 8
#define ledC2 9
#define ledC3 10
#define ledD1 12
#define ledD2 11
#define ledD3 13
#define sensorA A0
#define sensorB A1
#define sensorC A2
#define sensorD A3
int a1, b1, c1, d1;
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(sensorA, INPUT);
pinMode(sensorB, INPUT);
pinMode(sensorC, INPUT);
pinMode(sensorD, INPUT);
}
void loop() {
readSensor();
if (b1 == 1) {
roadBopen();
}
else if (d1 == 1 && b1 == 0) {
roadDopen();
if (b1 == 1 && b2 == 1) {
roadBopen();
}
}
else if (a1 == 1 && ((d1 == 0 || b1 == 0))) {
roadAopen();
if (b1 == 1) {
roadBopen();
}
else if (d1 == 1 && b1 == 0) {
roadDopen();
}
}
else if (c1 == 1 || (d1 == 0 || b1 == 0 || a1 == 0)) {
roadCopen();
if (b1 == 1) {
roadBopen();
}
else if (d1 == 1 && b1 == 0) {
roadDopen();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (b1 == 1 && (c1 == 1 || d1 == 1 || b1 == 1)) {
roadBopen();
}
else if (d1 == 1 && (c1 == 1 || a1 == 1) && (b1 == 0)) {
roadDopen();
}
else if ((a1 == 1) && (c1 == 1) && (d1 == 0) && (b1 == 0)) {
roadAopen();
}
else if ((c1 == 1) && (b1 == 0) && (d1 == 0) && (a1 == 0)) {
roadCopen();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
else if ((b1 == 1) && (c1 == 0) && (d1 == 0) && (a1 == 0)) {
roadBopen();
}
else if ((d1 == 1) && (c1 == 0) && (b1 == 0) && (a1 == 0)) {
roadDopen();
}
else if ((a1 == 1) && (c1 == 0) && (d1 == 0) && (b1 == 0)) {
roadAopen();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
else if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
roadBopen();
if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
roadDopen();
}
if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
roadAopen();
}
if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
roadCopen();
}
}
}
void readSensor() {
a1 = digitalRead(sensorA);
b1 = digitalRead(sensorB);
c1 = digitalRead(sensorC);
d1 = digitalRead(sensorD);
Serial.print(a1);
Serial.print("\t");
Serial.print(b1);
Serial.print("\t");
Serial.print(c1);
Serial.print("\t");
Serial.print(d1);
Serial.print("\t");
}
void roadAopen() {
digitalWrite(ledA3, LOW);
digitalWrite(ledA1, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(10000);
digitalWrite(ledA1, LOW);
digitalWrite(ledA2, HIGH);
delay(1000);
digitalWrite(ledA2, LOW);
}
void roadBopen() {
digitalWrite(ledB3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB1, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(10000);
digitalWrite(ledB1, LOW);
digitalWrite(ledB2, HIGH);
delay(1000);
digitalWrite(ledB2, LOW);
}
void roadCopen() {
digitalWrite(ledC3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC1, HIGH);
digitalWrite(ledD3, HIGH);
delay(10000);
digitalWrite(ledC1, LOW);
digitalWrite(ledC2, HIGH);
delay(1000);
digitalWrite(ledC2, LOW);
}
void roadDopen() {
digitalWrite(ledD3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD1, HIGH);
delay(10000);
digitalWrite(ledD1, LOW);
digitalWrite(ledD2, HIGH);
delay(1000);
digitalWrite(ledD2, LOW);
}