Sep 25, 2015

C++ OOP and classes: a clear explanation. Example of time-based scheduler

Use the millis() function, create instances of a class to create a clean scheduler with your Arduino code.  See time-based multitasking on the arduino by Bill Earl on Adafruit site.

Here's a snippet of the result of instances of LED flashing and Servo sweeping from his example:


...
 
Flasher led1(11, 123, 400);
Flasher led2(12, 350, 350);
Flasher led3(13, 200, 222);
 
Sweeper sweeper1(15);
Sweeper sweeper2(25);

void setup()
{
  Serial.begin(9600);
  sweeper1.Attach(9);
  sweeper2.Attach(10);
}

void loop()
{
  sweeper1.Update();
  sweeper2.Update();
  led1.Update();
  led2.Update();
  led3.Update();
}