file2.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Test the same as example#2:
  2. // Initially only tasks 1 and 2 are enabled
  3. // Task1 runs every 2 seconds 10 times and then stops
  4. // Task2 runs every 3 seconds indefinitely
  5. // Task1 enables Task3 at its first run
  6. // Task3 run every 5 seconds
  7. // loop() runs every 1 second (a default scheduler delay, if no shorter tasks' interval is detected)
  8. // Task1 disables Task3 on its last iteration and changed Task2 to run every 1/2 seconds
  9. // Because Task2 interval is shorter than Scheduler default tick, loop() executes ecery 1/2 seconds now
  10. // At the end Task2 is the only task running every 1/2 seconds
  11. //Header that declares all shared objects between .cpp files
  12. #include "header.hpp"
  13. #include <Arduino.h> //for Serial and delay
  14. Scheduler runner; //Let the scheduler live here, in the main file, ok?
  15. //Pretend, that the t2 task is a special task,
  16. //that needs to live in file2 object file.
  17. void t2Callback() {
  18. Serial.print("t2: ");
  19. Serial.println(millis());
  20. }
  21. Task t2(3000, TASK_FOREVER, &t2Callback, &runner, true);
  22. //Lets define t3Callback here. We are going to use it in file1
  23. //for Task 1.
  24. void t3Callback() {
  25. Serial.print("t3: ");
  26. Serial.println(millis());
  27. }
  28. void setup () {
  29. Serial.begin(115200);
  30. delay(5000);
  31. Serial.println("Scheduler TEST (multi-tab)");
  32. runner.startNow(); // set point-in-time for scheduling start
  33. }
  34. void loop () {
  35. runner.execute();
  36. // Serial.println("Loop ticks at: ");
  37. // Serial.println(millis());
  38. }