Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "driver/gpio.h"
- #include "button.h"
- #define GPIO_BUTTON GPIO_NUM_1
- void button_init(void)
- {
- gpio_config_t io_config ={};
- io_config.pin_bit_mask= 1ULL << GPIO_BUTTON;
- io_config.mode = GPIO_MODE_INPUT;
- io_config.pull_up_en = GPIO_PULLUP_ENABLED;
- io_config.pulldown_en = GPIO_PULLDOWN_DISABLE;
- io_config.intr_type = GPIO_INTR_DISABLE;
- gpio_config(&io_conf);
- }
- button_state_t button_get(void)
- {
- uint8_t pin_level;
- button_state_t state;
- pin_level = gpio_get_level(GPIO_BUTTON);
- if (pin_level == 1)
- {
- state = BUTTON_PRESSED;
- }
- else
- {
- state = BUTTON_RELEASED;
- }
- return state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement