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

button long-press & short press implement on nRF52

I am very new begginer and dont know where to start about nordic nrf52832 chip. Started a week ago with downloading SDK and playing with examples in it.

I in specific need some guidance to operate the long press and short press on same button and thereby make different functions in response to long or short press of button. Do you have any examples or guidlines for this?

In detail, i Want to make long press of button to perform one task, and short press of button to perform other task. I just want to get to know how the buttons are coded for detecting and performing the task. i Saw many posts in this website but couldnot find any coding example.

Parents Reply Children
  • yeah exactly, but i want to implement without connecting to softdevice and BLE.

    I just want to detect long press and detect short press and there by perform  small functionalities like prining basing upon the type of pressing.

  • If you look at the code(bsp.c), you can use it without the BLE function.
  • okay, will try using this. But since I am begginer, I just want to sample codes if there are any!


    And also, I need to use the timer right? for making funtionality? So just want to know where do we start timer and detect the press if we use bsp.c

  • Hey , I used both push, and long push used in bsp.h, 

    The functions in the following code in bsp.h are those which I called in main.c

    case APP_BUTTON_PUSH:
    event = m_events_list[button].push_event;
    //if (m_events_list[button].long_push_event != BSP_EVENT_NOTHING)
    {
    err_code = app_timer_start(m_button_timer_id, BSP_MS_TO_TICK(BSP_LONG_PUSH_TIMEOUT_MS), (void*)&current_long_push_pin_no);
    if (err_code == NRF_SUCCESS)
    {
    current_long_push_pin_no = pin_no;
    }
    }
    release_event_at_push[button] = m_events_list[button].release_event;
    break;


    case APP_BUTTON_RELEASE:
    (void)app_timer_stop(m_button_timer_id);
    if (release_event_at_push[button] == m_events_list[button].release_event)
    {
    event = m_events_list[button].release_event;
    }
    break;


    case BSP_BUTTON_ACTION_LONG_PUSH:
    event = m_events_list[button].long_push_event;
    press = 2; // long

    The thing is that short push is working fine, but for long push button, the output detected is related to both the short push and long push. Its just not giving the output of long push.

  • Hi,

    This is expected. The APP_BUTTON_PUSH from the app_button library is on a different "level" (app button library) then BSP_BUTTON_ACTION_LONG_PUSH (BSP library). app_button itself only support button press and release events, and has no concept of the duration of the pushes. 

    If you want t use BSP_BUTTON_ACTION_LONG_PUSH to get long pushes, then it makes sense to use the BSP_BUTTON_ACTION_PUSH event for the short/normal push, ignoring the app_button events.

Related