#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// #include "driver/gpio.h"
#include "freertos/semphr.h"
void taskSerial1(void * pvParameters);
void taskSerial2(void * pvParameters);
SemaphoreHandle_t Binary_Semaphore;
void setup()
{
Serial.begin(9600);
xTaskCreate(&taskSerial1, "taskSerial1", 4096, NULL, 1, NULL);
xTaskCreate(&taskSerial2, "taskSerial2", 4096, NULL, 1, NULL);
Binary_Semaphore = xSemaphoreCreateBinary();
//Semaphore Give
//Semaphore Take
xSemaphoreGive(Binary_Semaphore);
}
void taskSerial1(void * pvParameters)
{
for(;;)
{
xSemaphoreTake(Binary_Semaphore, portMAX_DELAY); // wait forever
Serial.println("I am in task Serial 1");
xSemaphoreGive(Binary_Semaphore);
vTaskDelay(30/portTICK_PERIOD_MS);
}
}
void taskSerial2(void * pvParameters)
{
for(;;)
{
xSemaphoreTake(Binary_Semaphore, portMAX_DELAY);
Serial.println("I am in task Serial 2");
xSemaphoreGive(Binary_Semaphore);
vTaskDelay(30/portTICK_PERIOD_MS);
}
}
void loop(){}