-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTimer.cpp
44 lines (35 loc) · 898 Bytes
/
Timer.cpp
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
/*Written by Jacob Smith for Brandeis Robotics club
Keeps track of current time
March 15 2018*/
//this should work on all boards, so there is no preprocessor directive here
//include all of the classes necessary to make this one work
#include <Arduino.h>
#include <Timer.h>
//Timer constructor
Timer::Timer(){
initTime=millis();
}
//resets the initial time
long Timer::resetTime () {
initTime=millis();
return getTime();
}
//returns the current time
long Timer::getTime(){
return millis()-initTime;
}
//returns the current time and resets the initial time
long Timer::getAndResetTime(){
long curTime=getTime();
resetTime();
return curTime;
}
//keeps track of a specified interval, so a procedure can be performed every second for example
bool Timer::interval(long interval){
bool intPassed=false;
if (getTime()>interval){
intPassed=true;
resetTime();
}
return intPassed;
}