//listing 6.1 Non-Blocking polling example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define BUTTON_PIN 4 // Button connected to GPIO4
void app_main() {
gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
gpio_set_pull_mode(BUTTON_PIN, GPIO_PULLUP_ONLY);
while (1) {
int pushButtonState = gpio_get_level(BUTTON_PIN);
printf("Waiting for event...\n");
if (pushButtonState == 0) {
printf("Button pressed! Handling event...\n");
} else {
printf("Event did not happen\n");
}
printf("Doing other tasks...\n");
vTaskDelay(pdMS_TO_TICKS(500));
}
}