// Basics of learning Free RTOS in Arduino
//Blinking an LED with Free Rtos and ESp32
// First include the header for RTOS
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
//==========================================================//
TaskHandle_t Blinking = NULL;
TaskHandle_t Printing = NULL;
#define LED 4
/*--------------------------------------------------------------------------------*/
// Write a funcion that will be performed when the first task is called.
void Blinking_Task(void *arg)
{
while(1){ // The loop starts here
digitalWrite(LED, HIGH);
vTaskDelay(500/ portTICK_RATE_MS); // vTaskDelay is the sleep time or delay time
digitalWrite(LED, LOW);
vTaskDelay(500/ portTICK_RATE_MS);
}
}
// Write a second function for the second task
void LED_status(void *param){
for(;;){
Serial.println("LED ON");
vTaskDelay(500/ portTICK_RATE_MS);
Serial.println("LED OFF");
vTaskDelay(500/ portTICK_RATE_MS);
}
}
/*------------------------------------------------------------------------------*/
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
xTaskCreate(Blinking_Task, // Function that implements the task.
"Blinking_Task", // Task name in text
4096, // Stack size in bytes, not words.
NULL, // Parameter of the function (*void arg)
10, // Task priority
&Blinking // Task handler that we created above
);
xTaskCreate(LED_status, "LED_status", 3000, NULL, 10, &Printing);
}