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

Long button press detection

Hello everyone,

I'm programming nRF52833 for my own application. In my application, I have a button to turn on and turn off the supplier. There is only 1 button so that I decided to have a plan like this:

  1. If I press the button and hold it for 1 sec, I turn the device on
  2. If I press the button and hold it for 3 secs, the device turns off

So that I have some following questions:

  1. How can I do it with BSP? I have read many topics related to my topic but I really don't understand how can they do it with a time they want. So please tell me something about it?
  2. My application using FREERTOS, so is that possible to do what I aforementioned using FREERTOS???

Thanks,

Best regards,

  • Hi,

    BSP only implements support for one Long press button action (in addition to push and release actions). If you want multiple long-push actions, you must implement this yourself in your application. You can use app_button together with app_timer to control the button actions. Start the two timers when the button is pushed, and set flags in the timer timeout handlers indicating if the timers has expired, and check the flags in the button handler when the button released event is generated, to determine the length of the button press.

    This should work fine together with FreeRTOS, just make sure you use the freertos implementation of app_timer.

    Best regards,
    Jørgen

Related