summaryrefslogtreecommitdiff
path: root/examples/Scheduler_example01
diff options
context:
space:
mode:
authorAnatoli Arkhipenko <arkhipenko@hotmail.com>2015-12-23 17:04:21 -0500
committerAnatoli Arkhipenko <arkhipenko@hotmail.com>2015-12-23 17:12:06 -0500
commit965f1b768d3d0675e2483ca62fa6d0565c389a31 (patch)
tree8bae4e1eee8275efaab252b35cb26c6a304fb015 /examples/Scheduler_example01
parent42d8d776e3fdb3c48700a3d88c8615dbf81da23f (diff)
Version 2.0.0 support for layered task prioritizationv2.0.0
* _TASK_PRIORITY - support for layered task prioritization
Diffstat (limited to 'examples/Scheduler_example01')
-rw-r--r--examples/Scheduler_example01/Scheduler_example01.ino84
1 files changed, 84 insertions, 0 deletions
diff --git a/examples/Scheduler_example01/Scheduler_example01.ino b/examples/Scheduler_example01/Scheduler_example01.ino
new file mode 100644
index 0000000..2175e57
--- /dev/null
+++ b/examples/Scheduler_example01/Scheduler_example01.ino
@@ -0,0 +1,84 @@
+/**
+ * TaskScheduler Test
+ *
+ * Initially only tasks 1 and 2 are enabled
+ * Task1 runs every 2 seconds 10 times and then stops
+ * Task2 runs every 3 seconds indefinitely
+ * Task1 enables Task3 at its first run
+ * Task3 run every 5 seconds
+ * Task1 disables Task3 on its last iteration and changed Task2 to run every 1/2 seconds
+ * At the end Task2 is the only task running every 1/2 seconds
+ */
+
+
+#include <TaskScheduler.h>
+
+// Callback methods prototypes
+void t1Callback();
+void t2Callback();
+void t3Callback();
+
+//Tasks
+Task t4();
+Task t1(2000, 10, &t1Callback);
+Task t2(3000, TASK_FOREVER, &t2Callback);
+Task t3(5000, TASK_FOREVER, &t3Callback);
+
+Scheduler runner;
+
+
+void t1Callback() {
+ Serial.print("t1: ");
+ Serial.println(millis());
+
+ if (t1.isFirstIteration()) {
+ runner.addTask(t3);
+ t3.enable();
+ Serial.println("t1: enabled t3 and added to the chain");
+ }
+
+ if (t1.isLastIteration()) {
+ t3.disable();
+ runner.deleteTask(t3);
+ t2.setInterval(500);
+ Serial.println("t1: disable t3 and delete it from the chain. t2 interval set to 500");
+ }
+}
+
+void t2Callback() {
+ Serial.print("t2: ");
+ Serial.println(millis());
+
+}
+
+void t3Callback() {
+ Serial.print("t3: ");
+ Serial.println(millis());
+
+}
+
+void setup () {
+ Serial.begin(115200);
+ Serial.println("Scheduler TEST");
+
+ runner.init();
+ Serial.println("Initialized scheduler");
+
+ runner.addTask(t1);
+ Serial.println("added t1");
+
+ runner.addTask(t2);
+ Serial.println("added t2");
+
+ delay(5000);
+
+ t1.enable();
+ Serial.println("Enabled t1");
+ t2.enable();
+ Serial.println("Enabled t2");
+}
+
+
+void loop () {
+ runner.execute();
+} \ No newline at end of file