-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtime.h
More file actions
45 lines (36 loc) · 1021 Bytes
/
time.h
File metadata and controls
45 lines (36 loc) · 1021 Bytes
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
// The Timer
#define PIN_CLK 14
#define PIN_DIO 15
SevenSegmentExtended timer(PIN_CLK, PIN_DIO);
unsigned long seconds = 0;
int mins = TIMER_MINUTES, sec = TIMER_SECONDS + 1;
void timeSetup() {
timer.begin(); // initializes the display
timer.setBacklight(100); // set the brightness to 100%
};
// function that displays the time on the clock
void displayTime()
{
if (seconds < millis())
{
seconds += 1000;
sec--;
if (sec == -1)
{
mins--;
if (mins == -1) bombExploded(); // if the time hits zero, the bomb will go off
else sec = 59;
}
if (mins == -1) timer.printTime(0, 0, true);
else timer.printTime(mins, sec, true);
}
}
void timeLoop() {
// defused : time left
// exploded from time : 00:00
// exploded from strikes : exploded
if (exploded && explodedFromStrikes)
timer.print(" BOMB EXPLODED ");
else if (!defused && !(exploded && !explodedFromStrikes))
displayTime();
}