-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.pde
More file actions
37 lines (28 loc) · 763 Bytes
/
Copy pathTimer.pde
File metadata and controls
37 lines (28 loc) · 763 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
////////////////////////////////////////////
// Useful timer class. Returns time in
// floating point seconds
class Timer{
int startMillis = 0;
float lastNow;
public Timer(){
start();
}
// call this to reset the timer
void start(){
startMillis = millis();
lastNow = 0;
}
// returns the elapsed time since you last called this function
// or since start() if it's the first time called
float getElapsedTime(){
float now = getTimeSinceStart();
float elapsedTime = now - lastNow;
lastNow = now;
return elapsedTime;
}
// call this to get the time since you called start() or
// instantiated the object
float getTimeSinceStart(){
return ((millis()-startMillis)/1000.0);
}
}