Created
June 6, 2016 02:29
-
-
Save futureshocked/d18bc5e09f57f0ca5ac429133b49318b to your computer and use it in GitHub Desktop.
This sketch demonstrates the use of the Scheduler library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * | |
| * This sketch demonstrates the use of the | |
| * Scheduler library. | |
| * | |
| * To use, you will need an Arduino Due or Zero, | |
| * four LEDs, four 220Ohm resistors, jumper wires | |
| * and a breadboard. | |
| * Connect the LEDs to a resistor, and the resistors | |
| * to pins 11, 10, 9, 8 on the Due. | |
| * Connect the cathode (short pin) of the LEDs | |
| * The the Due GND pin. | |
| * | |
| * Written by Peter Dalmaris | |
| * June 2016 | |
| * wwww.txplore.com | |
| */ | |
| #include <Scheduler.h> | |
| int led_red = 11; | |
| int led_green = 10; | |
| int led_yellow = 9; | |
| int led_orange = 8; | |
| void setup() { | |
| // put your setup code here, to run once: | |
| pinMode(led_red, OUTPUT); | |
| pinMode(led_green, OUTPUT); | |
| pinMode(led_yellow, OUTPUT); | |
| pinMode(led_orange, OUTPUT); | |
| Scheduler.startLoop(control_red); | |
| Scheduler.startLoop(control_green); | |
| Scheduler.startLoop(control_yellow); | |
| Scheduler.startLoop(control_orange); | |
| } | |
| void loop() { | |
| yield(); // This is important. With yield, control will be passed to one of the other tasks. | |
| // The same can be achieved by calling the delay function. | |
| } | |
| void control_red(){ | |
| digitalWrite(led_red, HIGH); | |
| delay(300); // Control is passed to one of the other tasks. | |
| digitalWrite(led_red, LOW); | |
| delay(300); // Control is passed to one of the other tasks. | |
| } | |
| void control_green(){ | |
| digitalWrite(led_green, HIGH); | |
| delay(400); // Control is passed to one of the other tasks. | |
| digitalWrite(led_green, LOW); | |
| delay(400); // Control is passed to one of the other tasks. | |
| } | |
| void control_yellow(){ | |
| digitalWrite(led_yellow, HIGH); | |
| delay(500); // Control is passed to one of the other tasks. | |
| digitalWrite(led_yellow, LOW); | |
| delay(500); // Control is passed to one of the other tasks. | |
| } | |
| void control_orange(){ | |
| digitalWrite(led_orange, HIGH); | |
| delay(600); // Control is passed to one of the other tasks. | |
| digitalWrite(led_orange, LOW); | |
| delay(600); // Control is passed to one of the other tasks. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment