MultiTask.ino 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <M5Stack.h>
  2. void task1(void * pvParameters) {
  3. for(;;) {
  4. Serial.print("task1 Uptime (ms): ");
  5. Serial.println(millis());
  6. delay(100);
  7. }
  8. }
  9. void task2(void * pvParameters) {
  10. for(;;) {
  11. Serial.print("task2 Uptime (ms): ");
  12. Serial.println(millis());
  13. delay(200);
  14. }
  15. }
  16. void task3(void * pvParameters) {
  17. for(;;) {
  18. Serial.print("task3 Uptime (ms): ");
  19. Serial.println(millis());
  20. delay(1000);
  21. }
  22. }
  23. void setup() {
  24. M5.begin();
  25. M5.Power.begin();
  26. // Task 1
  27. xTaskCreatePinnedToCore(
  28. task1, /* Function to implement the task */
  29. "task1", /* Name of the task */
  30. 4096, /* Stack size in words */
  31. NULL, /* Task input parameter */
  32. 1, /* Priority of the task */
  33. NULL, /* Task handle. */
  34. 0); /* Core where the task should run */
  35. // Task 2
  36. xTaskCreatePinnedToCore(
  37. task2, /* Function to implement the task */
  38. "task2", /* Name of the task */
  39. 4096, /* Stack size in words */
  40. NULL, /* Task input parameter */
  41. 2, /* Priority of the task */
  42. NULL, /* Task handle. */
  43. 0); /* Core where the task should run */
  44. // Task 3
  45. xTaskCreatePinnedToCore(
  46. task3, /* Function to implement the task */
  47. "task3", /* Name of the task */
  48. 4096, /* Stack size in words */
  49. NULL, /* Task input parameter */
  50. 3, /* Priority of the task */
  51. NULL, /* Task handle. */
  52. 0); /* Core where the task should run */
  53. }
  54. void loop() {
  55. M5.update();
  56. }