#include <Arduino.h>
SemaphoreHandle_t xMutex;
void taskA(void *pvParameters)
{
while (true)
{
// Wacht tot er een waarde beschikbaar is
if (xSemaphoreTake(xMutex, portMAX_DELAY) == pdTRUE)
{
Serial.println("--- Task a ---");
Serial.println("Waarde : 42");
Serial.println("-------------");
xSemaphoreGive(xMutex);
}
vTaskDelay(pdMS_TO_TICKS(600));
}
}
void taskB(void *pvParameters)
{
while (true)
{
// Wacht tot er een waarde beschikbaar is
if (xSemaphoreTake(xMutex, portMAX_DELAY) == pdTRUE)
{
Serial.println("--- Task b ---");
Serial.println("Teller : 7");
Serial.println("-------------");
xSemaphoreGive(xMutex);
}
vTaskDelay(pdMS_TO_TICKS(900));
}
}
void setup()
{
Serial.begin(115200);
xTaskCreate(
taskA,
"taskA",
2048,
NULL,
1,
NULL
);
xTaskCreate(
taskB,
"taskB",
2048,
NULL,
1,
NULL
);
}
void loop() {}