Hey all,
In a recent project I had use for a scheduler library which I ended up writing for myself.
It’s been working very nicely and I thought it might be nice to share with the community.
The code can be found in Particle_Scheduler. The way I use it is by copying over the header and cpp file into my project (wasn’t sure how else to do it).
Example usage as I use it in my project:
#include "scheduling.h";
// Duration
typedef unsigned int Duration;
const Duration Millisecond = 1;
const Duration Second = 1000 * Millisecond;
const Duration Minute = 60 * Second;
const Duration Hour = 60 * Minute;
// Setup scheduler
Scheduler sch = Scheduler();
void setup() {
sch.add(1200 * Millisecond, &fOne); // run every 1.2 seconds
sch.add(30 * Minute, &fTwo); // run every 30 minutes
sch.add(1 * Hour, &fThree); // and so on..
sch.add(24 * Hour, &fFour);
}
void loop() {
sch.run();
}
// some random functions
void fOne() {
Serial.println("1");
}
void fTwo() {
Serial.println("2");
}
void fThree() {
Serial.println("3");
}
void fFour() {
Serial.println("4");
}
It’s fairly simple but I’d be happy if this ended up useful to someone else.
Best,
Or