88 */
99#include < TaskManagerIO.h>
1010
11+ // here we define 4 PWM capable pins to connect the LEDs to, the LED controllers will be defined further down.
12+ const int blueLedPin = 6 ;
13+ const int redLedPin = 5 ;
14+ const int yellowLedPin = 10 ;
15+ const int greenLedPin = 11 ;
16+
17+ //
18+ // We use instances of a class extending executable, this allows us to store state for each LED and be called by task
19+ // manager on the schedule we define, it will call back the exec() method. This holds the LED pin and if the pin is
20+ // inverted, IE if the connection is reversed and the LED is on when LOW.
21+ //
1122class LedControlTask : public Executable {
1223private:
1324 pintype_t pin;
@@ -32,18 +43,22 @@ public:
3243 }
3344};
3445
35- LedControlTask blueLed (6 );
36- LedControlTask redLed (5 );
37- LedControlTask greenLed (11 , true );
38- LedControlTask yellowLed (10 );
46+ // define the 4 LED controllers globally
47+
48+ LedControlTask blueLed (blueLedPin);
49+ LedControlTask redLed (redLedPin);
50+ LedControlTask greenLed (greenLedPin, true );
51+ LedControlTask yellowLed (yellowLedPin);
3952
4053void setup () {
54+ // when we initialise them, they start a schedule with task manager.
4155 blueLed.init ();
4256 redLed.init ();
4357 greenLed.init ();
4458 yellowLed.init ();
4559}
4660
61+ // as with all task manager based programs, you must call the runLoop method frequently.
4762void loop () {
4863 taskManager.runLoop ();
4964}
0 commit comments