I will be maintaining my libraries here:
http://bit.ly/pATDBi

I am the lead developer for libraries 
that ship with the Wiring distribution. 
As per version 1.0 -
Wiring will support Arduino boards.
You are welcome to check it out!
http://wiring.org.co/download/
Scheduler Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com


Navigation


Current version

1.0 2009-05-09: Initial Release


History

1.0 2009-05-09: Initial Release


Description

Scheduler is a library for the Arduino.

It is created to help scheduling of function calls, and hide the underlying Arduino API calls.


Download, install and import

Download here: Scheduler.zip

Put the Scheduler folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Scheduler".
Once the library is imported, an "#include <Scheduler.h>" line will appear at the top of your Sketch.


Creation

Scheduler()

Scheduler scheduler = Scheduler();

Initializes an Scheduler object ready to queue function calls.


Functions

void update()

Checks to see if it is time for a function to be called, if so, call it and remove it from queue.

void schedule(function,unsigned int time)

Schedules a function call that should take place in time milliseconds.


Example

  1. #include <Scheduler.h> // [url=http://playground.arduino.cc/uploads/Code/Scheduler.zip]Scheduler.zip[/url]
  2.  
  3. Scheduler scheduler = Scheduler();      //create a scheduler
  4.  
  5. const byte ledPin = 13;               //LED on pin 13
  6.  
  7. void setup(){
  8.   Serial.begin(9600);                 //Iitialize the UART
  9.   pinMode(ledPin,OUTPUT);             //set pin 13 to OUTPUT
  10. }
  11.  
  12. void loop(){
  13.   scheduler.update();                 //update the scheduler, maybe it is time to execute a function?
  14.  
  15.   if (Serial.available()){            //if we have recieved anything on the Serial
  16.     scheduler.schedule(setHigh,500);  //schedule a setHigh call in 500 milliseconds
  17.     Serial.flush();                   //flush Serial so we do not schedule multiple setHigh calls
  18.   }
  19. }
  20.  
  21. void setHigh(){
  22.   digitalWrite(ledPin,HIGH);          //set ledPin HIGH
  23.   scheduler.schedule(setLow,500);     //schedule setLow to execute in 500 milliseconds
  24. }
  25.  
  26. void setLow(){
  27.   digitalWrite(ledPin,LOW);           //set ledPin LOW
  28. }
  29.  


FAQ

How can I use multiple Schedulerrs?

Scheduler is a class. You can initialize multiple instances by repeating what you've already seen:

Scheduler scheduler = Scheduler();

You could add a Scheduler called scheduler2 by

Scheduler scheduler2 = Scheduler();

And now it's just to call the functions you need on the Scheduler you are interested in:

//update Schedulers
  scheduler.update();
  scheduler2.update();


Information about this page

Part of AlphaBeta Libraries.
Last Modified: July 27, 2011, at 12:07 PM
By: AlphaBeta

Share