From 1972f6c168cd8d90a20a57e79d38e5f6c6a32711 Mon Sep 17 00:00:00 2001 From: Advaith Menon Date: Sun, 16 Nov 2025 02:41:42 -0500 Subject: [PATCH] Add test program for button inputs * Allow esp_driver_gpio privilege * Remove restart code * Add test program to read input buttons --- main/CMakeLists.txt | 3 ++- main/hello_world_main.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 28ab405..3aeb4cc 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,4 @@ idf_component_register(SRCS "hello_world_main.c" - PRIV_REQUIRES spi_flash + INCLUDE_DIRS "." + PRIV_REQUIRES spi_flash esp_driver_gpio INCLUDE_DIRS "") diff --git a/main/hello_world_main.c b/main/hello_world_main.c index 7010f3e..08f0329 100644 --- a/main/hello_world_main.c +++ b/main/hello_world_main.c @@ -12,6 +12,13 @@ #include "esp_chip_info.h" #include "esp_flash.h" #include "esp_system.h" +#include "driver/gpio.h" + +#define BUTTON_WHITE 0 +#define BUTTON_GREEN 10 +#define BUTTON_YELLOW 11 +#define BUTTON_BLUE 18 +#define BUTTON_RED 15 void app_main(void) { @@ -42,6 +49,22 @@ void app_main(void) printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); + gpio_set_direction(BUTTON_WHITE, GPIO_MODE_INPUT); + gpio_pullup_en(BUTTON_WHITE); + + gpio_set_direction(BUTTON_GREEN, GPIO_MODE_INPUT); + gpio_pullup_en(BUTTON_GREEN); + + gpio_set_direction(BUTTON_YELLOW, GPIO_MODE_INPUT); + gpio_pullup_en(BUTTON_YELLOW); + + gpio_set_direction(BUTTON_BLUE, GPIO_MODE_INPUT); + gpio_pullup_en(BUTTON_BLUE); + + gpio_set_direction(BUTTON_RED, GPIO_MODE_INPUT); + gpio_pullup_en(BUTTON_RED); + + /* for (int i = 10; i >= 0; i--) { printf("Restarting in %d seconds...\n", i); vTaskDelay(1000 / portTICK_PERIOD_MS); @@ -49,4 +72,14 @@ void app_main(void) printf("Restarting now.\n"); fflush(stdout); esp_restart(); + */ + while (1) { + printf("Button levels: [%d|%d|%d|%d|%d]\n", + gpio_get_level(BUTTON_WHITE), + gpio_get_level(BUTTON_GREEN), + gpio_get_level(BUTTON_YELLOW), + gpio_get_level(BUTTON_BLUE), + gpio_get_level(BUTTON_RED)); + vTaskDelay(500 / portTICK_PERIOD_MS); + } } -- 2.47.3