-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
47 lines (41 loc) · 679 Bytes
/
Copy pathTimer.cpp
File metadata and controls
47 lines (41 loc) · 679 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
/*
* Timer.cpp
*
* Created on: 23.06.2015
* Author: Moritz Scholjegerdes
*/
#include "Timer.h"
#include "Arduino.h"
Timer::Timer (void)
{
t_start = millis ();
}
unsigned long
Timer::since_seconds (void)
{
unsigned long seconds;
seconds = t_since_start () / 1000;
return seconds;
}
unsigned long
Timer::t_since_start (void)
{
unsigned long t;
t = millis ();
if (t < t_start) // detect overflow of millis ()
{
unsigned int t2;
t2 = 4294967295 - t_start; // time from t_start to overflow of millis ()
t = t + t2;
}
else
{
t = t - t_start;
}
return t;
}
void
Timer::restart (void)
{
t_start = millis ();
}