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

How the change the outcome of a button press action in nRF51 DK using app_button?

Hello!

I just want to change the outcome of Button 1 press action in my nRF 51 Dk. For example, instead of toggling led 1, I want to toggle pin 5. How to actually do that? I fiddled with the code, but up to now, no advance.

P.s.: I am using ble_app_hrs_c as my base code.

Thanks!!

  • My solution:

    What I did:

    1. Searched in bsp_btn_ble.c the function advertising_buttons_configure().

    2. Commented line bsp_event_to_button_action_assign(BTN_ID_SLEEP, BTN_ACTION_SLEEP, BSP_EVENT_SLEEP);. Commenting this line will prevent led 1 from stop/start blinking - and the nRF51 DK to enter/exit sleep mode.

    3. In main.c, function bsp_event_handler(), I expanded the switch statement to contain case BSP_EVENT_KEY_0. The BSP_EVENT_KEY_0 word is the default event passed to bsp_event_handler() when a button is pressed. So, the resulting code is:

    /* ...before cases */

    	case BSP_EVENT_KEY_0:
    
    		nrf_gpio_cfg_output(5);
    
    		nrf_gpio_pin_toggle(5);
    
    		break; 
    

    /* ... after cases */

    It's a little unpolished code edit, but for a first approach/learning, its OK.

  • Hello, Martin. Thanks for all sugestions. I fiddled with the code a little more and I think I managed to do what I want to do... Check my answer!

Related