/*In this basic free RTOS tutorial will use xTaskCreatePinnedToCore() .
in order to enable us to select which ESP32 core (core 0 or core 1) will run the particular task.*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define buzer 4
#define LED 15
TaskHandle_t buzerTask = NULL; // Task handler for the buzer function
TaskHandle_t LEDBlinking = NULL; /// Task handler fot the LED Task
//==========================================================================================//
// Function to be implemented when the buzer task is called
void Buzer_Task(void *param){
while(true){
Serial.println("Buzer_Task To Core1");
tone(buzer, 600);
vTaskDelay(500/ portTICK_RATE_MS);
tone(buzer, 500);
vTaskDelay(400/ portTICK_RATE_MS);
tone(buzer, 400);
vTaskDelay(300/ portTICK_RATE_MS);
tone(buzer, 350);
vTaskDelay(250/ portTICK_RATE_MS);
tone(buzer, 300);
vTaskDelay(200/ portTICK_RATE_MS);
tone(buzer, 250);
vTaskDelay(150/ portTICK_RATE_MS);
}
}
//==============================================================================================//
// Function to be implemented the LED task is called
void BlinkingLED(void *arg){
for(;;){
Serial.println("LED_Task To Core0");
digitalWrite(LED, HIGH);
vTaskDelay(250/ portTICK_RATE_MS);
digitalWrite(LED, LOW);
vTaskDelay(250/ portTICK_RATE_MS);
}
}
//===========================================================================================//
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED, OUTPUT);
Serial.println("Hello, ESP32 with FreeRTOS !");
}
void loop() {
// put your main code here, to run repeatedly:
xTaskCreatePinnedToCore(
Buzer_Task, // Function to be performed the task is called
"Buzer_Task", // Name of the task in text
4096, // Stack size (Memory size assigned to the task)
NULL, // Pointer that will be used as the parameter for the task being created
5, // Task Priority
&buzerTask, // The task handler
1 //xCoreID (Core 1)
);
xTaskCreatePinnedToCore(BlinkingLED, "BlinkingLED",3000, NULL, 10, &LEDBlinking, 0);
}