#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
// Define the GPIO pin connected to the button
#define BUTTON_PIN GPIO_NUM_3 // Change this if using a different GPIO pin
void app_main() {
// Configure the button pin as an input with an internal pull-up resistor
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << BUTTON_PIN),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&io_conf);
printf("Button Polling Example\n");
while (1) {
// Read the state of the button (HIGH if pressed, LOW if not)
int buttonState = gpio_get_level(BUTTON_PIN);
// Check if the button is pressed
if (buttonState == 0) {
printf("Button Pressed\n");
} else {
printf("Button Released\n");
}
// Add a small delay to avoid flooding the Serial Monitor
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}