#include <Arduino.h>
SemaphoreHandle_t xSemaphore;
byte buttonPin = 4 ;
void knopTask(void *pvParameters)
{
while (true)
{
if (digitalRead(4) == LOW) {
xSemaphoreGive(xSemaphore);
vTaskDelay(pdMS_TO_TICKS(200));
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void actieTask(void *pvParameters)
{
while (true)
{
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE)
{
Serial.println("Knop ingedrukt! Actie uitvoeren...");
}
}
}
void setup()
{
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
xSemaphore = xSemaphoreCreateBinary();
if (xSemaphore == NULL) {
Serial.println("Semaphore aanmaken mislukt!");
while (true);
}
xTaskCreate(
knopTask,
"knopTask",
2048,
NULL,
2,
NULL
);
xTaskCreate(
actieTask,
"actieTask",
2048,
NULL,
1,
NULL
);
}
void loop() {}