const uint8_t BUTTON_PIN = 4;
const uint8_t LED_PIN = 2;
TaskHandle_t taskControlHandle;
void taskButton(void *pvParams) {
while (1) {
if (digitalRead(BUTTON_PIN) == LOW) {
xTaskNotify(taskControlHandle, 0x01, eSetValueWithOverwrite);
vTaskDelay(pdMS_TO_TICKS(200)); // Debounce
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}
void taskControl(void *pvParams) {
uint32_t receivedValue;
while (1) {
if (xTaskNotifyWait(0, ULONG_MAX, &receivedValue, portMAX_DELAY) == pdTRUE) {
if (receivedValue == 0x01) {
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
Serial.println("LED alternado!");
}
}
}
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
xTaskCreate(taskControl, "Control", 2048, NULL, 1, &taskControlHandle);
xTaskCreate(taskButton, "Button", 2048, NULL, 1, NULL);
}
void loop() {}