-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.ino
93 lines (77 loc) · 1.66 KB
/
Queue.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
const int LEEG = 0;
const int STOPLICHT_1 = 1;
const int STOPLICHT_2 = 2;
const int SLAGBOOM = 3;
int queue[] = {0, 0, 0, 0};
int queueLijst[] = {LEEG, STOPLICHT_1, STOPLICHT_2, SLAGBOOM};
int queueLenght = sizeof(queue) / sizeof(int);
int queueLijstLength = sizeof(queueLijst) / sizeof(int);
void loopqueue() {
if (getButton(0)) {
queueStopLicht1();
}
if (getButton(1)) {
queueStopLicht2();
}
if (getButton(2)) {
queueSlagBoom();
}
}
void queueStopLicht1() {
addToQueue(STOPLICHT_1);
}
void queueStopLicht2() {
addToQueue(STOPLICHT_2);
}
void queueSlagBoom() {
addToQueue(SLAGBOOM);
}
//klaar
int getAndRemoveFirstFromQueue() {
int terug = aanDeBeurt();
verwijdereerste();
return terug;
}
//klaar
boolean queueCheck(int x) {
for (int i = 0; i < getQueueLencht(); i++) {
if (queue[i] == x) {
return true;
}
}
return false;
}
//klaar
void addToQueue(int x) {
// Serial.println("addToQueu");
if (!queueCheck(x)) {
// Serial.println("queuecheck");
// x = constrain(x , queueLijst[0], queueLijst[queueLijstLength]);
for (int i = 0; i < getQueueLencht(); i++) {
// Serial.println("for_loop");
if (queue[i] == LEEG) {
// Serial.println("isleeg");
queue[i] = x;
return;
}
}
}
}
//klaar
int aanDeBeurt() {
return queue[0];
}
//klaar
void verwijdereerste() {
for (int i = 0; i < getQueueLencht() - 1; i++) {
queue[i] = queue[i + 1];
}
queue[getQueueLencht() - 1] = LEEG;
}
//klaar
int getQueueLencht() {
return queueLenght;
}
int getQueue(int i) {
return queue[i];
}