-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopwatch.cpp
52 lines (38 loc) · 1.24 KB
/
Stopwatch.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
44
45
46
47
48
49
50
51
52
/*
Stopwatch.cpp - Library for timing.
Created by Božo Durdov, April 16, 2019.
Released into the public domain.
*/
#include "Arduino.h"
#include "Stopwatch.h"
Stopwatch::Stopwatch(){
};
char *Stopwatch::getValue(){
stpw.now=(millis()+stpw.elapsed)-stpw.initially;
int days = stpw.now / 86400000 ;
int hours = (stpw.now % 86400000) / 3600000;
int minutes = ((stpw.now % 86400000) % 3600000) / 60000 ;
int seconds = (((stpw.now % 86400000) % 3600000) % 60000) / 1000;
n=sprintf (buffer, "%02d day %02d : %02d : %02d", days, hours, minutes,seconds);
return buffer;
}
char *Stopwatch::getValueMinSec(){
stpw.now=(millis()+stpw.elapsed)-stpw.initially;
int minutes = ((stpw.now % 86400000) % 3600000) / 60000 ;
int seconds = (((stpw.now % 86400000) % 3600000) % 60000) / 1000;
n=sprintf (buffer, "%02d : %02d", minutes,seconds);
return buffer;
}
void Stopwatch::start(){
stpw.initially=millis();
}
void Stopwatch::stop(){
stpw.elapsed=millis()-stpw.initially;
stpw.initially=0;
}
void Stopwatch::reset(){
stpw.initially=0;
stpw.elapsed=0;
stpw.now=0;
days=hours=minutes=seconds=0;
}