-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (56 loc) · 1.48 KB
/
main.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
/* Imports */
#include <MicroBit.h>
#include <math.h>
/* Global Variables */
MicroBit hBit;
static const int DELAY_MS = 60000;
int is_paused = 0;
/* Function Prototypes */
void session(int length);
void pause_pressed(MicroBitEvent);
int main(int argc, char **argv) {
hBit.init();
hBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_DOWN, pause_pressed);
hBit.display.scroll("START");
session(25);
hBit.display.scroll("BREAK");
session(5);
hBit.display.clear();
hBit.display.scroll("END");
}
/* Functions */
void session(int length) {
for (int i = length; i > 0; i--) {
// Paused
while (is_paused == 1) {
hBit.sleep(1000);
}
int num_rows = ceil((double) i / 5);
int num_in_last_row = i % 5 == 0 ? 5 : i % 5;
hBit.display.print(i);
hBit.sleep(1000);
hBit.display.clear();
for (int row = 0; row < num_rows; row++) {
int num_columns = row == num_rows - 1 ? num_in_last_row : 5;
int column = 0;
for (column = 0; column < num_columns; column++) {
hBit.display.image.setPixelValue(row, column, 125);
}
// Remove the turned off ones
for (int off_col = row; off_col < 5; off_col++) {
hBit.display.image.setPixelValue(off_col, column, 0);
}
}
hBit.sleep(DELAY_MS);
}
}
void pause_pressed(MicroBitEvent) {
if (is_paused == 0) {
hBit.display.scroll("PAUSED");
is_paused = 1;
}
else {
hBit.display.scroll("RESUMED");
is_paused = 0;
}
}