-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrafficSimulation.ino
More file actions
55 lines (46 loc) · 1.24 KB
/
TrafficSimulation.ino
File metadata and controls
55 lines (46 loc) · 1.24 KB
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
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int GreenLed = 10;
const int YellowLed = 9;
const int RedLed = 8;
int state = 0; // State 0 - Red only, State 1 - Red Yellow, State 2 - Green
// State 3 - Yellow
int light_delay[] = { 2500, 2500, 2500, 2500 };
void setup() {
pinMode(GreenLed, OUTPUT);
pinMode(YellowLed,OUTPUT);
pinMode(RedLed,OUTPUT);
lcd.begin(16, 2);
}
void loop() {
switch (state) {
case 0 :
digitalWrite(YellowLed, LOW);
digitalWrite(RedLed, HIGH);
lcd.clear();
lcd.print("Don't Walk");
break;
case 1 :
digitalWrite(YellowLed, LOW);
break;
case 2 :
digitalWrite(YellowLed, LOW);
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, HIGH);
lcd.clear();
lcd.print("Walk");
break;
case 3 :
digitalWrite(GreenLed, LOW);
digitalWrite(YellowLed, HIGH);
lcd.clear();
lcd.print("Caution");
break;
}
delay(light_delay[state]);
if (state == 3) {
state = 0;
} else {
state += 1;
}
}