Skip to content

Cross-posted from my personal blog: http://www.meatandnetworking.com/code/introducing-arduino-simple-task-scheduler/

Get the code here: https://github.com/Zuph/AVRQueue

Introducing the Arduino Simple Task Scheduler.  This is part of the balloon flight computer code I wrote for White Star, with some more polish. This library allows you to create a schedule queue of functions to be executed at specified times, on specified intervals.  For example, say you're trying to log some sensor data and update a display in the same program. With the task scheduler, you can simply write a function to gather sensor data, write a function to update the display, add them to your queue, and let the library handle the rest.

This isn't really useful for blinking LEDs, but it's great for complex systems. For example, the balloon computer was gathering sensor data, sending short reports, sending long reports, monitoring vertical speed, monitoring GPS Status, monitoring flight state, managing ballast, and managing a backup high-frequency radio at the same time.  Halfway through development, it was obvious that we would need to integrate a watchdog timer to keep other systems from freezing the flight computer.  If all of these tasks had been occurring simultaneously, spread throughout spaghetti code, it would have been very difficult to add watchdog resets in all the right places.  With the task queue, I simply defined another function that reset the watchdog, and put it in the queue.  Two minutes, tops!

You can find extensive documentation and examples in the Github project.  To install, just copy the "Arduino" directory contents to the "Libraries" folder of your Arduino IDE install.  Restart your IDE, and it should pop right up.  Here's a really simple example program:

#include <Queue.h>

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);
    Serial.println("Alive");

    Queue myQueue;
    myQueue.scheduleFunction(testFunction, "Test", 5000, 1000);

    while(1) {
        myQueue.run(millis());
        delay(10);
    }
}

int testFunction(unsigned long now)
{
    Serial.print("Hello: ");
    Serial.println(now);
}

 

 This will print "Hello: X" where X is the number of milliseconds since startup, starting 5 seconds after startup, and repeating every 1 second.
The Arduino library has some limitations, so I've also included an AVR "library" (just a couple of source files to include in your project).  This one's a little easier to tweak to your specific application, and doesn't suffer some of the same drawbacks as the Arduino library.  That said, the Arduino library will be find for almost every project out there!  The limitations are listed in more detail at the Github site.
If you find any bugs, let me know! Submit a Github issue, fork, fix and submit a pull request, or contact me directly!  If you find this useful, let me know!  It isn't a lot, but I hope it's well documented, and easy to use/read/understand.

3

A big personal thanks to everyone who came out to the 2012 LVL1 Boneyard Hackathon.  We had 9 teams consisting of 54 hackers compete for 24 hours straight, putting to the test their technical capabilities, endurance, and creativity.  We had 9 great projects, and everyone had a lot of fun!  Our youngest competitors were only 11 years old! Everyone here already looks forward to the next event.

Thanks to Jon for recording a summary of the projects at the hackathon.  I'll upload a full video of the project showcase soon!

[youtube=http://www.youtube.com/watch?v=1maAoSg6Fdo]

Team Bloominglabs made an incredible 3 musical instruments, a mixer for them all, and a bunch of LED blinky stuff! They brought 9 hackers to bring this all together, and were a flurry of activity throughout the hackathon.

DSC_0728.JPG

The Raging Narwhals, a team from the Triangle Fraternity at LVL1, made a floppy drive keyboard. Unfortunately, it wasn't quite working by the end, but it was an impressive effort, and they plan to come back to finish it up. They brought a huge team, and almost all of them stayed through the night!

DSC_0737.JPG

The LVL1 Stonecutters managed to make a 3-D Scanner and Animated Gif Maker using the parts in the boneyard!

DSC_0740.JPG

Team Rainbow Unicorn built a first place trophy, so even if they failed, they would win.

DSC_0748.JPG

The Dirty Cheaters put together an incredibly impressive Rock 'em, Sock 'em robots kit, which included rack and pinion steering, and no microcontrollers.

DSC_0754.JPG

Destined for Failure built a looping synthesizer controlled by a PS2 mouse. Very impressive, especially consdiering this was the group's first foray into Arduino progrmaming!

DSC_0761.JPG

Team Polar Bear build a laser pong game, complete with scorekeeping, 8 bit sound effects, and varying difficulty levels. Superb engineering, guys!

DSC_0756.JPG

The Noobs were our youngest team, and they put together a custom computer using parts from the basement, including custom LED signs.

DSC_0765.JPG

Finally, Bob the Bodybuilder built a very loud keypad controlled synthesizer. They even devised a means to convert sheet music to keypad tablature.

DSC_0769.JPG

I owe a huge thanks to everyone involved. Thanks to FoodCalc Inc. (http://www.foodcalc.com) for supplying libation for the event. Thanks to Joe L. for helping out throughout the event. Thanks to Gary F. for being a trooper, staying way later than he meant to, and helping out almost every team here. Thanks to Jose C. for taking way more crap than he deserved. Thanks to Lauren, Jynn, and Steph for acting as team breakfast, and keeping us all from starving.

Plenty more photos on the flickr stream. Peruse through, and if this interest you, come to our space! Links above and to the right will help you find us.