Pages: [1]   Go Down
Author Topic: New library: The Run Library  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
#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
« Last Edit: November 12, 2012, 08:22:24 pm by billroy » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13702
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: