New library: The Run Library

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: https://github.com/billroy/run

-br http://bitlash.net

Thanks for sharing,

Can you explain why you cast m=millis() to signed long in the runner() ?

I assume you do it to make the code overflow proof? Can you proof it is overflow proof? (I don't want to test for ~25 days to check :)