-
Notifications
You must be signed in to change notification settings - Fork 0
Timer.h
Brandon W. Kipp edited this page Feb 13, 2020
·
1 revision
This library is used to handle common timer-related functions. Currently, it does timing by counting from millis() although, in the future, micros() may be implemented.
To setup a new Timer, you'll need to pass in two parameters:
-
void (*callback)(boolean, boolean, unsigned long), a callback function that accepts the returnedintvalue of the sensor -
unsigned long, the duration of the timer
| Method | Arguments | Returns | Description |
|---|---|---|---|
| postpone | (unsigned long postponeAmount) | void | Resets the timer's duration to postponeAmount, provided in ms. |
#include "Libraries/Button.h"
#include "Libraries/Timer.h"
Button button1;
Timer timer1;
void setup() {
timer1.setup([](boolean running, boolean ended, unsigned long timeElapsed) {
if (running == true) {
// Let's make sure a light is on!
}
if (ended == true) {
// Time's up! Lights out.
}
}, 3000);
button1.setup(button1Pin, [](int state) {
if (state == 1) {
if (timer1.isRunning() == false) {
timer1.start();
}
else {
timer1.postpone(3000);
}
}
});
}
void loop() {
timer1.update();
}