#include <Arduino.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
// Define LED pin numbers
#define LED_1 2
#define LED_2 4
#define LED_3 5
// Task function for blinking the first red LED
void taskRedLED1(void *parameter) {
while (1) {
digitalWrite(LED_1, HIGH);
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1 second
digitalWrite(LED_1, LOW);
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1 second
}
}
// Task function for blinking the second red LED
void taskRedLED2(void *parameter) {
while (1) {
digitalWrite(LED_2, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS); // Delay for 0.5 seconds
digitalWrite(LED_2, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS); // Delay for 0.5 seconds
}
}
// Task function for blinking the third red LED
void taskRedLED3(void *parameter) {
while (1) {
digitalWrite(LED_3, HIGH);
vTaskDelay(250 / portTICK_PERIOD_MS); // Delay for 0.25 seconds
digitalWrite(LED_3, LOW);
vTaskDelay(250 / portTICK_PERIOD_MS); // Delay for 0.25 seconds
}
}
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Initialize the three LED pins as outputs
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
// Create tasks for each LED
xTaskCreate(taskRedLED1, "RedLED1Task", 1000, NULL, 1, NULL);
xTaskCreate(taskRedLED2, "RedLED2Task", 1000, NULL, 1, NULL);
xTaskCreate(taskRedLED3, "RedLED3Task", 1000, NULL, 1, NULL);
// Start the FreeRTOS scheduler
vTaskStartScheduler();
}
void loop() {
// Print a debug message
Serial.println("This should never be reached because FreeRTOS is managing the tasks");
delay(1000); // Add a delay to avoid spamming the serial output
}