-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube.ino
65 lines (51 loc) · 1.3 KB
/
cube.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
// #include "LowPower.h"
#include "cube.hpp"
#include "gameengine.hpp"
#include "animator.hpp"
// #include "freemem.h"
Cube cube;
Animator anim(&cube);
GameEngine ge(&cube, &anim);
Level * current_level = nullptr;
void setup() {
// Begin serial
Serial.begin(115200);
while (!Serial)
delay(10);
// Init cube
cube.init();
}
void loop() {
long time = millis();
// Level update
if (current_level == nullptr or current_level->is_over()) {
bool is_success = true;
if (current_level != nullptr) {
// Remove the previous level
is_success = current_level->is_success();
delete current_level;
}
// Reset the cube leds
cube.reset_leds();
// Serial.print("Base mem ");Serial.println(freeMemory());
if (is_success) {
// Load new level
current_level = ge.load_next_lvl();
} else {
// Reload level
current_level = ge.reload_lvl();
}
// Serial.print("Lvl loaded mem ");Serial.println(freeMemory());
}
// Trigger all the waiting callbacks
if(!digitalRead(INT_PIN)){
cube.read(false);
}
// Refresh cube displays
anim.next_cycle();
cube.show();
// Wait a small delay (max 10 fps to save power)
time = millis() - time;
delay(max(0, REFRESH_DELAY-time));
// LowPower.idle((int)max(0, REFRESH_DELAY-time));
}