Scheduler_example09_TimeCritical.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * TaskScheduler Test
  3. * Illustration of use of Time Critical Information
  4. *
  5. * Task1 runs every 1 second indefinitely
  6. * On each run it reports how delayed the invokation of the callback method was,
  7. * and what was the scheduling overun.
  8. * Each run task 1 is dealyed randomly for up to 2 seconds, thus simulating scheduling overrun
  9. */
  10. #define _TASK_TIMECRITICAL
  11. #define _TASK_SLEEP_ON_IDLE_RUN
  12. #include <TaskScheduler.h>
  13. // Callback methods prototypes
  14. void t1Callback();
  15. //Tasks
  16. Task t1(1000, -1, &t1Callback);
  17. Scheduler runner;
  18. void t1Callback() {
  19. Serial.print(millis());
  20. Serial.print(": overrun = ");
  21. Serial.print(t1.getOverrun());
  22. Serial.print(", start delayed by ");
  23. Serial.println(t1.getStartDelay());
  24. int i = random(2000);
  25. Serial.print("Delaying for "); Serial.println(i);
  26. delay(i);
  27. }
  28. void setup () {
  29. Serial.begin(115200);
  30. Serial.println("Scheduler TimeCritical TEST");
  31. runner.init();
  32. Serial.println("Initialized scheduler");
  33. runner.addTask(t1);
  34. Serial.println("added t1. Waiting for 5 seconds.");
  35. delay(5000);
  36. t1.enable();
  37. Serial.println("Enabled t1");
  38. }
  39. void loop () {
  40. runner.execute();
  41. }