#include <Arduino_FreeRTOS.h>
#include <semphr.h>
SemaphoreHandle_t mutex_v;
void setup() {
Serial.begin(9600);
mutex_v = xSemaphoreCreateMutex();
if (mutex_v == NULL) {
Serial.println("Mutex can not be created");
}
pinMode(2, INPUT_PULLUP);
xTaskCreate(Task1, "Led", 128, NULL, 0, NULL );
xTaskCreate(Task2, "LedBlink", 128, NULL, 0, NULL );
}
void Task1(void *pvParameters) {
while(1) {
pinMode(8, OUTPUT);
xSemaphoreTake(mutex_v, portMAX_DELAY);
digitalWrite(8, HIGH);
Serial.println("Hi from Task1");
xSemaphoreGive(mutex_v);
digitalWrite(8, LOW);
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
void Task2(void *pvParameters) {
while(1) {
pinMode(7, OUTPUT);
xSemaphoreTake(mutex_v, portMAX_DELAY);
digitalWrite(7, HIGH);
Serial.println("Hi from Task2");
xSemaphoreGive(mutex_v);
digitalWrite(7, LOW);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void loop() {
}