// Define a task handle and initialize it to NULL
TaskHandle_t task2_handle = NULL;
//Explains how to suspend/restart tasks as required:https://savjee.be/videos/programming-esp32-with-arduino/manage-freertos-tasks/
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
xTaskCreatePinnedToCore(task1,
"Task1",
2048,
NULL,
1,
NULL,
1);
xTaskCreatePinnedToCore(task2,
"Task2",
2048,
NULL,
1,
&task2_handle,
1);
delay(5000); //Delay 5 Seconds
Serial.println("Calling Function");
manualTask();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void task1(void* parameters){
while(1){
Serial.println("Task 1");
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for half a second
}
}
void task2(void* parameters){
while(1){
Serial.println("Task 2");
vTaskDelay( 500 / portTICK_PERIOD_MS ); // wait for half a second
}
}
void manualTask(){
Serial.println("Function manual Task Run");
Serial.println("Stopping task 2 for 5 seconds");
vTaskSuspend(task2_handle);
delay(5000);
Serial.println("Resuming task 2");
vTaskResume(task2_handle);
}