#include <stdio.h>
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define BUTTON_GPIO 2 // GPIO pin for the button
#define LED_GPIO 5 // GPIO pin for the LED
void setup() {
// Initialize the button and LED GPIO pins
gpio_pad_select_gpio(BUTTON_GPIO);
gpio_set_direction(BUTTON_GPIO, GPIO_MODE_INPUT);
gpio_pad_select_gpio(LED_GPIO);
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
}
void loop() {
int button_state = gpio_get_level(BUTTON_GPIO); // Read button state
if (button_state == 0) { // If button is pressed
gpio_set_level(LED_GPIO, 0); // Turn off LED
vTaskDelay(5 / portTICK_PERIOD_MS); // Delay for 5 ms
} else {
gpio_set_level(LED_GPIO, 1); // Turn on LED
}
}
void app_main() {
setup(); // Call setup function
while (1) {
loop(); // Call loop function repeatedly
}
}