Advertisement
aperles

Untitled

Mar 5th, 2025
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "driver/gpio.h"
  2. #include "button.h"
  3.  
  4. #define GPIO_BUTTON GPIO_NUM_1
  5.  
  6. void button_init(void)
  7. {
  8.     gpio_config_t io_config ={};
  9.     io_config.pin_bit_mask= 1ULL << GPIO_BUTTON;
  10.     io_config.mode = GPIO_MODE_INPUT;
  11.     io_config.pull_up_en = GPIO_PULLUP_ENABLED;
  12.     io_config.pulldown_en = GPIO_PULLDOWN_DISABLE;
  13.     io_config.intr_type = GPIO_INTR_DISABLE;
  14.     gpio_config(&io_conf);
  15. }
  16.  
  17. button_state_t button_get(void)
  18. {
  19.     uint8_t pin_level;
  20.     button_state_t state;
  21.  
  22.     pin_level = gpio_get_level(GPIO_BUTTON);
  23.     if (pin_level == 1)
  24.     {
  25.         state = BUTTON_PRESSED;
  26.     }
  27.     else
  28.     {
  29.         state = BUTTON_RELEASED;
  30.     }
  31.     return state;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement