-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerkeersSimulatie.ino
180 lines (163 loc) · 3.53 KB
/
VerkeersSimulatie.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
#include <Servo.h>
unsigned long currentMillis;
unsigned long previousMillis;
unsigned long previousMillisQ;
int verkeersState;
const int START = 0;
const int DodeTijd = 1;
const int STOPLICHTEEN = 2;
const int STOPLICHTTWEE = 3;
const int VEKEERSLAGBOOM = 4;
const int QUEUE = 5;
const int NACHT = 6;
int getqueue;
void setup() {
serialSetup();
ledControlSetup();
setupBUTTONS();
setupStand();
Serial.println("v0.09");
setupStopLicht();
setupSlagboom();
verkeersState = START;
}
void loop() {
currentMillis = millis();
loopBUTTONS(currentMillis);
loopqueue();
loopStand();
// test();
printQueue();
loopStoplicht(currentMillis);
verkeerregelaar(currentMillis);
loopSlagBoom(currentMillis);
}
void verkeerregelaar(int currentMillis) {
switch (verkeersState) {
case START:
exit_Start();
verkeersState = DodeTijd;
entry_dodeTijd();
break;
case DodeTijd:
if (currentMillis - previousMillis >= 1000) {
exit_dodetijd();
verkeersState = QUEUE;
enter_queue();
}
break;
case STOPLICHTEEN:
if (!getStoplichtStatus(0)) {
exit_stopLicht();
verkeersState = DodeTijd;
entry_dodeTijd();
}
break;
case STOPLICHTTWEE:
if (!getStoplichtStatus(1)) {
exit_stopLicht();
verkeersState = DodeTijd;
entry_dodeTijd();
}
break;
case VEKEERSLAGBOOM:
if (getslagboom()) {
exit_slagboom();
verkeersState = DodeTijd;
entry_dodeTijd();
}
break;
case QUEUE:
do_queue();
if (getqueue == 1) {
//stoplicht 1
exit_queue();
verkeersState = STOPLICHTEEN;
entry_lichteen();
break;
}
if (getqueue == 2) {
//stoplicht 2
exit_queue();
verkeersState = STOPLICHTTWEE;
entry_lichttwee();
break;
}
if (getqueue == 3) {
exit_queue();
verkeersState = VEKEERSLAGBOOM;
entry_slagboom();
break;
}
break;
case NACHT:
do_nacht();
if (getDagStand()) {
exit_nacht();
verkeersState = START;
enter_start();
}
break;
}
}
void entry_dodeTijd() {
previousMillis = currentMillis;
}
void exit_dodetijd() {
previousMillis = currentMillis;
}
void exit_Start() {
// ledControlTurnAllOff();
}
void enter_start() {
// ledControlTurnAllOn();
}
void exit_stopLicht() {
getAndRemoveFirstFromQueue();
}
void entry_lichteen() {
startStopLicht(0);
}
void entry_lichttwee() {
startStopLicht(1);
}
void exit_slagboom() {
getAndRemoveFirstFromQueue();
}
void entry_slagboom() {
startSlagboom();
}
void enter_queue() {}
void exit_queue() {}
void exit_nacht() {}
void do_queue() {
getqueue = aanDeBeurt();
}
void do_nacht() {
startSlagboom();
}
//test voor button input
void test() {
for (int i = 0; i < 3; i++) {
if (getButton(i)) {
ledControlTurnOn(i);
} else {
ledControlTurnOff(i);
}
}
}
//code voor controleren van queue
void printQueue() {
if (currentMillis - previousMillisQ >= 1000) {
previousMillisQ = currentMillis;
Serial.println("====");
Serial.println("");
Serial.print(aanDeBeurt());
for (int i = 0; i < 4; i++) {
Serial.print(getQueue(i));
Serial.println("");
Serial.print(getButton(i));
}
Serial.println("");
}
}