-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
87 lines (76 loc) · 1.66 KB
/
timer.h
File metadata and controls
87 lines (76 loc) · 1.66 KB
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
bool timerUiShowing = false;
bool timerStarted = false;
bool timerDone = false;
unsigned long startTime;
unsigned long endTime;
float timeDelta;
int endSpeed = 60;
int lastProgress = 0;
bool timerArmed() {
return (!timerStarted && !timerDone) ?true :false;
}
bool timerRunning() {
return (timerStarted && !timerDone) ?true :false;
}
void timerUi() {
if (!timerUiShowing) {
myLCD.clear();
myLCD.setCursor(0,1);
myLCD.print("Timer");
myLCD.setCursor(0,2);
myLCD.print("0-60");
myLCD.setCursor(0,3);
myLCD.print(speedUnitName);
}
}
void timerMode() {
timerUi();
timerStarted = false;
timerDone = false;
lastProgress = 0;
}
void startTimer() {
startTime = micros();
timerStarted = true;
myLCD.setCursor(0,1);
myLCD.print("GO!!!!!");
}
void endTimer() {
timerDone = true;
timeDelta = endTime - startTime;
timeDelta /= 1000000;
myLCD.setCursor(0,0);
myLCD.print(" ");
myLCD.setCursor(0,0);
myLCD.print(timeDelta,3);
myLCD.print(" seconds nice.");
myLCD.setCursor(0,1);
myLCD.print("Timer ");
}
void progressBar(float speed) {
float twentieths = endSpeed / 20;
int progress = round(speed/twentieths);
char progressChars[21] = "";
if (progress != lastProgress){
lastProgress = progress;
for (int i = 0; i < 20; i++) {
if (progress > i) {
strcat(progressChars, "#" );
} else {
strcat(progressChars, " ");
}
}
myLCD.setCursor(0,0);
myLCD.print(progressChars);
}
}
void checkSpeed(float speed) {
if(!timerDone) {
if (speed >= endSpeed) {
endTime = micros();
endTimer();
} else {
progressBar(speed);
}
}
}