// Include required libraries
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define Blink_LED1 23
#define Blink_LED2 22
#define Blink_LED3 0
#define DELAY_TO_BE_USED 1
// Function declaration
void vBlinkLED1 (void *params);
void vBlinkLED2 (void *params);
void vBlinkLED3 (void *params);
TaskHandle_t TaskHandle_1; // handler for Task1
TaskHandle_t TaskHandle_2; // handler for Task2
TaskHandle_t TaskHandle_3; // handler for Task3
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// Configure LED pins as outputs
pinMode(Blink_LED1, OUTPUT);
pinMode(Blink_LED2, OUTPUT);
pinMode(Blink_LED3, OUTPUT);
// Create tasks
xTaskCreate(vBlinkLED1,"Task1",20000,NULL,3,&TaskHandle_1);
xTaskCreate(vBlinkLED2,"Task2",20000,NULL,2,&TaskHandle_2);
xTaskCreate(vBlinkLED3,"Task3",20000,NULL,1,&TaskHandle_3);
vTaskStartScheduler();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
// Task to blink LED1 at 1 Hz frequency, 50% duty cycle
void vBlinkLED1 (void *params)
{
while(1)
{
digitalWrite(Blink_LED1, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED1_ON\n");
vTaskDelay(pdMS_TO_TICKS(500)); // Adjust the delay as needed
digitalWrite(Blink_LED1, LOW); // turn the LED off by making the voltage LOW
Serial.println("LED1_OFF\n");
vTaskDelay(pdMS_TO_TICKS(500)); // Adjust the delay as needed
}
}
// Task to blink LED2 at 1 Hz frequency, 25% duty cycle
void vBlinkLED2 (void *params)
{
while(1)
{
digitalWrite(Blink_LED2, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED2_ON\n");
vTaskDelay(pdMS_TO_TICKS(250)); // Adjust the delay as needed // wait for a second
digitalWrite(Blink_LED2, LOW); // turn the LED off by making the voltage LOW
Serial.println("LED2_OFF\n");
vTaskDelay(pdMS_TO_TICKS(750)); // Adjust the delay as needed
}
}
// Task to blink LED3 at 1 Hz frequency, 75% duty cycle
void vBlinkLED3 (void *params)
{
while(1)
{
digitalWrite(Blink_LED3, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED3_ON\n");
vTaskDelay(pdMS_TO_TICKS(750)); // Adjust the delay as needed // wait for a second
digitalWrite(Blink_LED3, LOW); // turn the LED off by making the voltage LOW
Serial.println("LED3_OFF\n");
vTaskDelay(pdMS_TO_TICKS(250)); // Adjust the delay as needed
}
}