//FreeRTOS library:
#include <Arduino_FreeRTOS.h>
//Variables for buzzer & first 3 LEDs!
const int LED1 = 8; //Red LED
const int LED2 = 9; //Yellow LED
const int LED3 = 10; //Green LED
void setup() {
Serial.begin(9600);
//LEDs' initialization!
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
/*
Create 3 tasks with labels 'Task_1', 'Task_2' and 'Task_3' and
assign the priority as 1, 2 and 3 respectively.
*/
//'Neutral_Task' - the task-free function!
xTaskCreate(Task_1, "Task no. 1!", 100, NULL, 1, NULL);
xTaskCreate(Task_2, "Task no. 2!", 100, NULL, 2, NULL);
xTaskCreate(Task_3, "Task no. 3!", 100, NULL, 3, NULL);
xTaskCreate(Task_4, "Empty Task!", 100, NULL, 0, NULL);
}
//The following function is Task1. We display the task label on Serial monitor.
static void Task_3(void* pvParameters) {
while (1) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
Serial.println(F("Task no. 1!"));
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
//Task 2
static void Task_2(void* pvParameters) {
while (1) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
Serial.println(F("Task no. 2!"));
vTaskDelay(1100 / portTICK_PERIOD_MS);
}
}
//Task 3
static void Task_1(void* pvParameters) {
while (1) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
Serial.println(F("Task no. 3!"));
vTaskDelay(1200 / portTICK_PERIOD_MS);
}
}
//Task 4
static void Task_4(void* pvParameters) {
while (1) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
Serial.println(F("Empty Task!"));
vTaskDelay(1300 / portTICK_PERIOD_MS);
}
}
//We don't need to use "loop" function here!
void loop() {}