-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicroMetro.cpp
More file actions
51 lines (34 loc) · 719 Bytes
/
MicroMetro.cpp
File metadata and controls
51 lines (34 loc) · 719 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
47
48
49
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "MicroMetro.h"
MicroMetro::MicroMetro() {
this->interval = 1000;
}
MicroMetro::MicroMetro(unsigned long interval){
this->interval = interval;
}
void MicroMetro::setInterval(unsigned long interval){
this->interval = interval;
}
uint8_t MicroMetro::check() {
now = micros();
if ( interval == 0 ){
previous_time = now;
return 1;
}
if ( (now - previous_time) >= interval) {
#ifdef NOCATCH_UP
previous_time = now ;
#else
previous_time += interval ;
#endif
return 1;
}
return 0;
}
void MicroMetro::reset(){
this->previous_time = micros();
}