-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElapsedTimer.cpp
More file actions
35 lines (30 loc) · 900 Bytes
/
ElapsedTimer.cpp
File metadata and controls
35 lines (30 loc) · 900 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
/** A handy abstraction for calculating the amount of time
* that has elapsed since it was last reset
* Inspired by Qualcomm's ElapsedTimer
* @author Jordan Burklund
* @date Sept. 2015
**/
#include <Arduino.h>
#include "ElapsedTimer.h"
/** Constructor **/
ElapsedTimer::ElapsedTimer() {
startTimeMillis = millis();
startTimeMicros = micros();
}
/** Get the amount of elapsed time in milliseconds
* @return Amount of time since last reset in milliseconds
**/
unsigned long ElapsedTimer::getTimeMillis() {
return millis() - startTimeMillis;
}
/** Get the amount of elapsed time in microseconds
* @return Amount of time since last reset in microseconds
**/
unsigned long ElapsedTimer::getTimeMicros() {
return micros() - startTimeMicros;
}
/** Reset the elapsed time back to 0 **/
void ElapsedTimer::resetTimer() {
startTimeMillis = millis();
startTimeMicros = micros();
}