Enable Arduinos to run multiple tasks.
Switch branches/tags
Nothing to show
Clone or download
4
Latest commit 5785332 May 19, 2015
Permalink
Failed to load latest commit information.
TaskScheduler
.gitattributes
.gitignore init Jul 27, 2013
LICENSE Update LICENSE Mar 20, 2014
ReadMe.md Update ReadMe.md May 19, 2015

ReadMe.md

This is a task scheduler for Arduinos with a ATmega328p microcontroller. Inspired by Patterns for Time-Triggered Embedded Systems.

NOTE: This library uses Timer 1 on ATmega328p, so it is incompatible some libraries using the same timer. (Such as Servo, Mozzi, or analogWrite() on pin 9 and 10)

How to use?

STEP 1. Put Sch.init(); and Sch.start(); into void setup(), and put Sch.dispatchTasks(); into void loop(), like this:

void setup()
{
    // Your code...

    Sch.init();
    Sch.start();
}

void loop()
{
    Sch.dispatchTasks();
}

STEP 2. Put tasks at the end of your code, like this:

void setup()
{
    // Your code...

    Sch.init();
    Sch.start();
}

void loop()
{
    Sch.dispatchTasks();
}

// Tasks

void task1()
{
  // Your code...
}

void task2()
{
  // Your code...
}

STEP 3. Use Sch.addTask() between Sch.init(); and Sch.start(); to add tasks into the task scheduler, like this:

void setup()
{
    // Your code...

    Sch.init();
    
    Sch.addTask(task1,0,1000,1);  // Add task1. Starts at the 0th ms, and runs every 1000 ms
    Sch.addTask(task2,20,500,1);  // Add task2. Starts at the 20th ms, and runs every 500 ms
    
    Sch.start();
}

void loop()
{
    Sch.dispatchTasks();
}

中文简介在这里:http://blanboom.org/arduino-task-scheduler-library.html