#include <Arduino_FreeRTOS.h>
void setup()
#define T1_PERIOD 5
#define T1_EXEC_TIME 3
#define T2_PERIOD 8
#define T2_EXEC_TIME 3
//Initialize the Serial Monitor with 9600 baud rate
{
Serial.begin(9600);
Serial.println(F("In Setup function"));
//Set the digital pins 8 to 11 as digital output pins
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
//Create three tasks with labels Task1, Task2 and Task3 and assign the priority as 1, 2 and 3 respectively.
//We also create the fourth task labeled as IdelTask when there is no task in
//operation and it has the highest priority.
xTaskCreate(MyTask1, "Task1", 100, NULL, 1, NULL);
xTaskCreate(MyTask2, "Task2", 100, NULL, 2, NULL);}
//We can change the priority of task according to our desire by changing the numeric’s //between NULL texts.
void loop()
{
}
//The following function is Task1. We display the task label on Serial monitor.
static void MyTask1(void* pvParameters)
{
while(1)
{
digitalWrite(8,HIGH);
vTaskDelay(T1_EXEC_TIME/portTICK_PERIOD_MS);
digitalWrite(9,LOW);
vTaskDelay(T1_PERIOD - T1_EXEC_TIME/portTICK_PERIOD_MS);
}
}
//Similarly this is task 2
static void MyTask2(void* pvParameters)
{
while(1)
{ digitalWrite(8,HIGH);
vTaskDelay(T2_EXEC_TIME/portTICK_PERIOD_MS);
digitalWrite(9,LOW);
vTaskDelay(T2_PERIOD - T2_EXEC_TIME/portTICK_PERIOD_MS);
vTaskDelay(60/portTICK_PERIOD_MS);
Serial.print("Busy period length: ");
Serial.println(T2_PERIOD + T2_EXEC_TIME);
}
}