// Create 2 Tasks as Task 1 and Task 2,
// perform sync operation between these 2 tasks using Task Notification
// such that when Task 1 and Task 2 both print out their respective strings,
// both Tasks get synced and print out a string “Tasks Synced”.
#include <Arduino.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
TaskHandle_t Task1Handle = NULL;
TaskHandle_t Task2Handle = NULL;
void Task1(void *pvParameters) {
while (1) {
Serial.println("Task 1 Running");
// Notify Task 2 that Task 1 is done
xTaskNotifyGive(Task2Handle);
// Wait for notification from Task 2
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Serial.println("Tasks Synced");
delay(1000); // Add delay for demonstration purposes
}
}
void Task2(void *pvParameters) {
while (1) {
Serial.println("Task 2 Running\n");
// Notify Task 1 that Task 2 is done
xTaskNotifyGive(Task1Handle);
// Wait for notification from Task 1
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Serial.println("Tasks Synced");
delay(1000); // Add delay for demonstration purposes
}
}
void setup() {
// Initialize Serial communication
Serial.begin(115200);
delay(1000); // Give some time for the Serial monitor to start
// Create Task 1
xTaskCreate(Task1, "Task1", 10000, NULL, 1, &Task1Handle);
// Create Task 2
xTaskCreate(Task2, "Task2", 10000, NULL, 1, &Task2Handle);
}
void loop() {
// Nothing to do here
}