-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.pde
More file actions
executable file
·53 lines (43 loc) · 967 Bytes
/
timer.pde
File metadata and controls
executable file
·53 lines (43 loc) · 967 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
46
47
48
49
50
51
52
53
int lastUpdatedTimeAt;
final int TIMER_DRAW_INTERVAL = 1000;
class Timer {
int startTime = 0;
int stopTime = 0;
int turnDuration;
boolean running = false;
Timer(int tempTurnDuration){
turnDuration = tempTurnDuration;
}
void start(){
startTime = millis();
running = true;
}
void stop() {
stopTime = millis();
running = false;
}
int getElapsedTime() {
int elapsed;
if(running){
elapsed = (millis() - startTime);
}else{
elapsed = (stopTime - startTime);
}
return elapsed;
}
int getRemainingTime(){
return (turnDuration - getElapsedTime());
}
int second(){
return (getRemainingTime() / 1000) % 60;
}
int minute(){
return (getRemainingTime() / (1000*60)) % 60;
}
String formattedRemainingTimeForSvg(){
return nf(minute(), 1)+""+nf(second(), 2);
}
String formattedRemainingTime(){
return nf(minute(), 1)+":"+nf(second(), 2);
}
}