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

How can i stop execution of my program until button is pressed ?

Hi, i am using ble_app_hrs_c_pca10056_s140(nRF52840) and i want to stop execution of my program and based on button press return i want to continue my program.

i am unable to find the function used for button press?

please Help me how to do it. Thank you.

  • Hi!

    Define your button in this method:

    static void buttons_init(void) {
        // Note: Array must be static because a pointer to it will be saved in the Button handler
        //       module.
    
        static app_button_cfg_t buttons[] =
        {
            {BUTTON_2, false, BUTTON_PULL, button_event_handler}
        };
    
        app_button_init(buttons, 1, BUTTON_DETECTION_DELAY); }
    

    And define your event handler that you refer to in that method as well:

    static void button_event_handler(uint8_t pin_no,uint8_t button_action)
    {
       // Stop or start execution
    }
    

    And then just call buttons_init() in your main.

    This is how I do it when using S130 on nRF51822 but I guess this kind of stuff is the same on your setup.

    Kind regards

Related