Many posts here boil down to questions about how to run functions on a schedule. It's such a common requirement, I built it into Bitlash as the "run" command.
I've just posted a tiny library that lets you do the same thing in C from your Arduino sketch.
The Run library does one thing: it runs functions you specify, each at a specified interval.
Here's a sample sketch that toggles pin 13 every 100ms and pin 12 every 125ms:
#include "run.h"
void toggle13(void) {
digitalWrite(13, !digitalRead(13));
}
void toggle12(void) {
digitalWrite(12, !digitalRead(12));
}
void setup(void) {
pinMode(13, OUTPUT);
run(toggle13, 100); // call run() to run toggle13 every 100 ms
pinMode(12, OUTPUT);
run(toggle12, 125); // call run() to run toggle12 every 125 ms
}
void loop(void) {
runner(); // call runner() to run the function scheduler
}
The Run library on Github: GitHub - billroy/run: Arduino function scheduler library: runs your C function at a specified interval, like the Bitlash run command
-br