-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.cpp
111 lines (97 loc) · 2.2 KB
/
quiz.cpp
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
#include "./quiz.h"
int blink_times = 8;
int blink_delay = 250;
Quiz::Quiz() {
this->reset();
};
void Quiz::receive_1() {
this->startBlink(1);
};
void Quiz::receive_2() {
this->startBlink(2);
};
void Quiz::receive_3() {
this->startBlink(3);
};
void Quiz::receive_4() {
this->startBlink(4);
};
void Quiz::receive_5() {
this->startBlink(5);
};
void Quiz::receive_6() {
this->startBlink(6);
};
void Quiz::startBlink(int led) {
if (this->blinking == false) {
this->blinking = true;
this->blinkingButton = led;
}
}
void Quiz::reset() {
this->LED_1_STATE = 0;
this->LED_2_STATE = 0;
this->LED_3_STATE = 0;
this->LED_4_STATE = 0;
this->LED_5_STATE = 0;
this->LED_6_STATE = 0;
this->blinking = false;
this->blinkingButton = 0;
this->blinkCount = 0;
}
void Quiz::tick() {
if (this->blinking and (this->lastAction == 0 or (millis() - this->lastAction) >= blink_delay)) {
this->lastAction = millis();
if (this->blinkingButton == 1) {
if (this->LED_1_STATE == 0) {
this->LED_1_STATE = 1;
} else {
this->LED_1_STATE = 0;
this->blinkCount += 1;
}
}
else if (this->blinkingButton == 2) {
if (this->LED_2_STATE == 0) {
this->LED_2_STATE = 1;
} else {
this->LED_2_STATE = 0;
this->blinkCount += 1;
}
}
else if (this->blinkingButton == 3) {
if (this->LED_3_STATE == 0) {
this->LED_3_STATE = 1;
} else {
this->LED_3_STATE = 0;
this->blinkCount += 1;
}
}
else if (this->blinkingButton == 4) {
if (this->LED_4_STATE == 0) {
this->LED_4_STATE = 1;
} else {
this->LED_4_STATE = 0;
this->blinkCount += 1;
}
}
else if (this->blinkingButton == 5) {
if (this->LED_5_STATE == 0) {
this->LED_5_STATE = 1;
} else {
this->LED_5_STATE = 0;
this->blinkCount += 1;
}
}
else if (this->blinkingButton == 6) {
if (this->LED_6_STATE == 0) {
this->LED_6_STATE = 1;
} else {
this->LED_6_STATE = 0;
this->blinkCount += 1;
}
}
if (this->blinkCount >= blink_times) {
this->reset();
}
}
}