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

Detect button callback trigger

Hello,

In relation to button press detection, I'm curious if I'm utilizing both GPIO_INT_EDGE and GPIO_IN_DOUBLE_EDGE if I can pass the interrupt type to my callback to know whether it was triggered by rising or falling of the button? At the moment I'm doing this by keeping a count of button presses and then using basic math to determine if the value is even or odd. Even = button down, odd = button up. Is there a better way to do this?

Parents
  • Hello,

    There are a couple approaches for this. One is to actually read the pin state in the interrupt. 

    Do you use any libraries for your button handling? bsp or app_button, for example?

    If you want a bit more than just the basic button handler, such as whether the button was pressed or not, I would suggest that you look into using the app_button library directly (which is used by the bsp library). The reason for this is that the bsp library strips away quite a lot from the app_button functionality.

    If you take a closer look in the bsp example found in SDK\examples\peripheral\bsp, and look inside the bsp_init() function, you can see that it calls app_button_init(), with app_buttons as an argument. In app_buttons, there is an event handler; bsp_button_event_handler(). In this event handler you can see that it checks whether the button was pressed or released.

    NB: Note that the app_button library requires you to start the app_timer in order to work. (It is used for debounce)

    Best regards,

    Edvin

Reply
  • Hello,

    There are a couple approaches for this. One is to actually read the pin state in the interrupt. 

    Do you use any libraries for your button handling? bsp or app_button, for example?

    If you want a bit more than just the basic button handler, such as whether the button was pressed or not, I would suggest that you look into using the app_button library directly (which is used by the bsp library). The reason for this is that the bsp library strips away quite a lot from the app_button functionality.

    If you take a closer look in the bsp example found in SDK\examples\peripheral\bsp, and look inside the bsp_init() function, you can see that it calls app_button_init(), with app_buttons as an argument. In app_buttons, there is an event handler; bsp_button_event_handler(). In this event handler you can see that it checks whether the button was pressed or released.

    NB: Note that the app_button library requires you to start the app_timer in order to work. (It is used for debounce)

    Best regards,

    Edvin

Children
Related