Skip to main content

Button

This code initializes the board, registers two button event callbacks, and specifies the button events to be handled. When the user presses the button, the corresponding callback function will be called. The ESP_LOGI() function is used to print a message to the console indicating which button event occurred.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "esp_log.h"
#include "bsp_board.h"
#include "bsp_btn.h"


static void __btn_click_callback(void* arg)
{
ESP_LOGI("btn", "Click");

}

static void __btn_double_click_callback(void* arg)
{
ESP_LOGI("btn", "Double Click");
}

void app_main(void)
{
ESP_ERROR_CHECK(bsp_board_init());

/*
* Button Event types you can use:
* BUTTON_PRESS_DOWN
* BUTTON_PRESS_UP
* BUTTON_PRESS_REPEAT
* BUTTON_SINGLE_CLICK
* BUTTON_DOUBLE_CLICK
* BUTTON_LONG_PRESS_START
* BUTTON_LONG_PRESS_HOLD
*/
bsp_btn_register_callback( BOARD_BTN_ID_USER, BUTTON_SINGLE_CLICK, __btn_click_callback, NULL);
bsp_btn_register_callback( BOARD_BTN_ID_USER, BUTTON_DOUBLE_CLICK, __btn_double_click_callback, NULL);
}

Tech Support

Don't worry, we've got you covered! Please visit our Seeed Official Discord Channel to ask your questions!

If you have large order or customization requirement, please contact [email protected]

Loading Comments...