const int LED_BUILTIN = 2;
// setup function runs once - once press reset or power the board
void setup() {
pinMode (LED_BUILTIN, OUTPUT); // LED_BUILTIN as an output.
Serial.begin (115200);
xTaskCreatePinnedToCore (
loop2, // Function to implement the task
"loop2", // Name of the task
4000, // Stack size in bytes e.g 8 mb
NULL, // Task input parameter
0, // Priority of the task
NULL, // Task handle.
0 // Core where the task should run 0 or 1
);
xTaskCreatePinnedToCore (loop3,"loop3",4000,NULL,1,NULL,0);
}
void loop() {
// Main loop is unused
}
// the loop2 function also runs forver but as a parallel task
// on core 0
void loop2 (void* pvParameters) {
while (1) {
Serial.print ("Hello");
vTaskDelay (200); // wait for 0.2 second non blocking
Serial.println (" World");
vTaskDelay (500); // wait for half a second non blocking
}
}
// the loop3 function also runs forver but as a parallel task
// on core 0 slight change in timing may happen as per scheduling
void loop3 (void* pvParameters) {
while (1) {
digitalWrite (LED_BUILTIN, HIGH); // turn the LED on
vTaskDelay (1000); // wait for 2 seconds non blocking
digitalWrite (LED_BUILTIN, LOW); // turn the LED off
vTaskDelay (600); // wait for 2 seconds non blocking
}
}