-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.pde
96 lines (77 loc) · 1.5 KB
/
timer.pde
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
87
88
89
90
91
92
93
94
95
class Timer {
long startTime;
long currentTime;
boolean running=false;
boolean paused=false;
boolean theEnd=false;
long questionsTime=0;
long sessionTime=0;
long sessionTimeLeft=0;
long questionsTimeLeft=0;
boolean session=false;
Timer(long sT, long qT) {
questionsTime = qT;
sessionTime = sT;
running = false ;
currentTime = 0 ;
session=true;
theEnd=false;
}
float getCurrentTimeMs() {
if ( running )
return (millis() - startTime);
else
return currentTime ;
}
int getCurrentTimeSec() {
if ( running )
return ( (int) ( (millis() - startTime) / 1000.0) ) ;
else
return ( (int) (currentTime / 1000.0) ) ;
}
void start()
{
if (paused)
{
startTime = millis() - currentTime ;
running=true;
paused=false;
}
else if (!running) {
running = true ;
startTime = millis() ;
}
}
void pause()
{
if (running)
{
currentTime = millis() - startTime ;
running = false ;
paused=true;
}
}
float getSessionTimeLeft()
{
float tLeft = sessionTime-getCurrentTimeMs();
if (tLeft <= 0)
{
session=false;
running=false;
start();
}
return tLeft;
}
float getQuestionsTimeLeft()
{
float tLeft = questionsTime-getCurrentTimeMs();
if (tLeft <= 0)
{
session=true;
running=true;
theEnd=true;
startTime = millis() ;
}
return tLeft;
}
}