Simple Task Scheduler. For the moment only implements continuous running tasks and periodic tasks.

Example

two blinking leds

#include "mbed.h"

#include "task_scheduler.h"

Serial pc(USBTX, USBRX);        // tx, r

class Foo {
  DigitalOut myled1;
  int counter;

  public:
    Foo(void) :myled1(LED1) { counter = 0; }

    void alive_task(void) {
      if (counter++ % 30000 == 0) {
        myled1 = !myled1;
      }
    }
};

class Bar {
  DigitalOut myled2;

  public:
    Bar(void) :myled2(LED2) {}

    void control_task(void) {
      myled2 = !myled2;
    }
};

int main() {

    Foo foo;
    Bar bar;

    SimpleTaskScheduler::TaskScheduler scheduler;
    scheduler.create_continuous_task(&foo, &Foo::alive_task);
    scheduler.create_periodic_task(&bar, &Bar::control_task, 1);

    while(1) {
      scheduler.update();
    }
}