#include <Arduino_FreeRTOS.h>
//declare fuunction
void MyTask1(void*    pvparamenters);
void MyTask2(void*    pvParameters);
void MyTask3 (void*   pvParameters);


void setup()
{
Serial.begin(9600);//Initialize the Serial Monitor with 9600 baud rate
Serial.println(F("In Setup function"));// for print
   //Set the digital pins 8 to 11 as digital output pins
  pinMode(13,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(7,OUTPUT);
// api key xTaskCreate(MyTask_pointer, "task_name", stack size, Parameter, Priority, TaskHandle);
 xTaskCreate(MyTask1, "Task1", 120, NULL, 1, NULL);
 xTaskCreate(MyTask2, "Task2", 100, NULL, 2, NULL);
 xTaskCreate(MyTask3, "IdleTask", 100, NULL, 0, NULL);
 }

//We can change the priority of task according to our desire by changing the numeric’s //between NULL texts.


//The following function is Task1. We display the task label on Serial monitor.

void MyTask1(void* pvparameters)
{
   while(1)
  { 
    digitalWrite(13,HIGH);

    digitalWrite(9,LOW); 

    digitalWrite(7,LOW);

    Serial.println(F("Task1"));

    vTaskDelay(1200/portTICK_PERIOD_MS);
  }
}

//Similarly this is task 2
void MyTask2(void* pvParameters)
{  
while(1)
  { digitalWrite(13,LOW);
    digitalWrite(9,HIGH); 
    digitalWrite(7,LOW);
     Serial.println(F("Task2"));
    vTaskDelay(1100/portTICK_PERIOD_MS);
  }
}
//This is the idle task which has the lowest priority and calls when no task is running.
 void MyTask3(void* pvParameters)

{
  while(1)
   { 
    digitalWrite(13, HIGH);
    digitalWrite(9,LOW); 
   digitalWrite(7,HIGH);
    Serial.println(F("Idle state"));
    delay(1000); 
  }  
}

void loop()

{
//There is no instruction in the loop section of the code.
// Because each task executes on interrupt after specified time

}