Go Down

Topic: New library: The Run Library (Read 1 time) previous topic - next topic

billroy

Nov 13, 2012, 02:10 am Last Edit: Nov 13, 2012, 02:22 am by billroy Reason: 1
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: [Select]

#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

robtillaart

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 :)

Rob Tillaart

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy