Button Peripheral¶
To control application flow you may use buttons connected and read through the ESP32 GPIOs. This API provides functions to initialize specific GPIOs and obtain information on button events such as when it has been pressed, when released, when pressed for a long time and released after long press. To get information on a particular event, establish a callback function with button_dev_add_tap_cb()
or button_dev_add_press_cb()
.
Application Example¶
Implementation of this API is demonstrated in cloud_services/google_translate_device example.
API Reference¶
Header File¶
Functions¶
-
esp_periph_handle_t
periph_button_init
(periph_button_cfg_t *but_cfg)¶ Create the button peripheral handle for esp_peripherals.
- Note
The handle was created by this function automatically destroy when
esp_periph_destroy
is called- Return
The esp peripheral handle
- Parameters
but_cfg
: The but configuration
Structures¶
-
struct
periph_button_cfg_t
¶ The Button peripheral configuration.
Enumerations¶
-
enum
periph_button_event_id_t
¶ Peripheral button event id.
Values:
-
PERIPH_BUTTON_UNCHANGE
= 0¶ No event
-
PERIPH_BUTTON_PRESSED
¶ When button is pressed
-
PERIPH_BUTTON_RELEASE
¶ When button is released
-
PERIPH_BUTTON_LONG_PRESSED
¶ When button is pressed and kept for more than
long_press_time_ms
-
PERIPH_BUTTON_LONG_RELEASE
¶ When button is released and event PERIPH_BUTTON_LONG_PRESSED happened
-