-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.pde
More file actions
44 lines (38 loc) · 868 Bytes
/
Copy pathTimer.pde
File metadata and controls
44 lines (38 loc) · 868 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
class Timer {
int period;
boolean enabled;
int interrupt;
float startTick = 0;
float currentTick = 0;
float timelength;
int count;
Timer (int p) { // ex: Timer(300) for a 1/300th of a second timer
this.period = p;
this.timelength = 1000.0/p;
this.enabled = false;
this.interrupt = 0;
}
void enableTimer() {
this.enabled = true;
this.count = 0;
this.currentTick = millis();
this.startTick = this.currentTick;
}
void disableTimer() {
this.enabled = false;
}
void clearInt () {
this.interrupt = 0;
}
int getInt () {
return this.interrupt;
}
void runTimer() {
this.count++;
this.currentTick = millis();
if (this.currentTick > (this.startTick + this.timelength)) {
this.interrupt = 1;
this.enableTimer();
}
}
}