This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use more that 4 buttons??

Is there any way to use more than 4 buttons using app_button or BSP library? It seems that GPIOTE can handle only 4 pin. Am I right??

	uint32_t err_code;
// Button configuration structure.
static app_button_cfg_t p_button[] = {  {BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                        {BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                        {BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler},
                                        {BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}};

// Initializing the buttons.
err_code = app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), 50);
APP_ERROR_CHECK(err_code);
											
// Enabling the buttons.										
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);

My part of code is like this. I want to add BUTTON_5 using same button_handler. How can I add to it?? Thank you.

Parents
  • The "BSP" is the board support package for Nordic's developer boards. Since boards have limited numbers of buttons only a few buttons are defined, which is why it doesn't go up to BUTTON_5. The BUTTON_X #defines just designate which gpio pin will be used for the button. In the code you've included p_button is an array and you can put as many things in it as you'd like (up to the max of using all the available IO pins). To add another button just add a new item, like:

    {YOUR_BUTTONS_GPIO, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}
    

    Where "YOUR_BUTTONS_GPIO" is replaced with a GPIO pin number (or defined constant for the pin number).

Reply
  • The "BSP" is the board support package for Nordic's developer boards. Since boards have limited numbers of buttons only a few buttons are defined, which is why it doesn't go up to BUTTON_5. The BUTTON_X #defines just designate which gpio pin will be used for the button. In the code you've included p_button is an array and you can put as many things in it as you'd like (up to the max of using all the available IO pins). To add another button just add a new item, like:

    {YOUR_BUTTONS_GPIO, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}
    

    Where "YOUR_BUTTONS_GPIO" is replaced with a GPIO pin number (or defined constant for the pin number).

Children
Related