Scheduler_example6_IDLE.ino 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * This is a test to prove that processor really goes into IDLE sleep.
  3. * For this setup:
  4. *
  5. *
  6. Task c(10, -1, &Count, &ts);
  7. Task t(10000, 1, NULL, &ts, true, &tOn, &tOff);
  8. The result are:
  9. 1): With #define _TASK_SLEEP_ON_IDLE_RUN enabled
  10. Start
  11. c1=10771
  12. c2=1001
  13. and
  14. 2): With #define _TASK_SLEEP_ON_IDLE_RUN disabled (commented out)
  15. Start
  16. c1=529783
  17. c2=1001
  18. C1 is scenario 2) is much higher than in scenario 1) because processor is put to sleep for 1), but not for 2)
  19. */
  20. /**
  21. * Compile and run once with _TASK_SLEEP_ON_IDLE_RUN enabled, then with _TASK_SLEEP_ON_IDLE_RUN disabled.
  22. * Compare the results.
  23. */
  24. //#define _TASK_SLEEP_ON_IDLE_RUN
  25. #include <TaskScheduler.h>
  26. Scheduler ts;
  27. Task c(10, -1, &Count, &ts);
  28. Task t(10000, 1, NULL, &ts, true, &tOn, &tOff);
  29. volatile unsigned long c1, c2;
  30. bool tOn() {
  31. c1 = 0;
  32. c2 = 0;
  33. c.enable();
  34. return true;
  35. }
  36. void tOff() {
  37. c.disable();
  38. Serial.print("c1=");Serial.println(c1);
  39. Serial.print("c2=");Serial.println(c2);
  40. }
  41. void setup() {
  42. // put your setup code here, to run once:
  43. Serial.begin(115200);
  44. Serial.println("Start");
  45. t.delay();
  46. // ts.allowSleep(false);
  47. }
  48. void Count() {
  49. c2++;
  50. }
  51. void loop() {
  52. // put your main code here, to run repeatedly:
  53. ts.execute();
  54. c1++;
  55. }