#define buttonPin1 22
#define buttonPin2 4
#define ledPin1 23
#define ledPin2 2
SemaphoreHandle_t xSemaLED1;
SemaphoreHandle_t xSemaLED2;
TickType_t btnDebounce1 = 0;
TickType_t btnDebounce2 = 0;
void IRAM_ATTR ISR1() {
btnDebounce1 = xTaskGetTickCountFromISR();
xSemaphoreGiveFromISR(xSemaLED1, NULL);
}
void IRAM_ATTR ISR2() {
btnDebounce2 = xTaskGetTickCountFromISR();
xSemaphoreGiveFromISR(xSemaLED2, NULL);
}
void setup() {
Serial.begin(115200);
xSemaLED1 = xSemaphoreCreateBinary();
xSemaLED2 = xSemaphoreCreateBinary();
xTaskCreate(flashLED1, "Flash LED1", 1024 * 4, NULL, 1, NULL);
xTaskCreate(flashLED2, "Flash LED1", 1024 * 4, NULL, 1, NULL);
pinMode(buttonPin1, INPUT_PULLUP);
attachInterrupt(buttonPin1, ISR1, FALLING);
pinMode(buttonPin2, INPUT_PULLUP);
attachInterrupt(buttonPin2, ISR2, FALLING);
}
void flashLED1(void *pvParam) {
pinMode(ledPin1, OUTPUT);
while (1) {
xSemaphoreTake( xSemaLED1, portMAX_DELAY);
if ((xTaskGetTickCount() - btnDebounce1) < 100) {
digitalWrite(ledPin1, !digitalRead(ledPin1));
vTaskDelay(1000);
}
}
}
void flashLED2(void *pvParam) {
pinMode(ledPin2, OUTPUT);
while (1) {
xSemaphoreTake( xSemaLED2, portMAX_DELAY);
if ((xTaskGetTickCount() - btnDebounce2) < 100) {
digitalWrite(ledPin2, !digitalRead(ledPin2));
vTaskDelay(1000);
}
}
}
void loop() {}