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!!

Parents
  • Hi

    First of all, the example is using the Button Support Package (BSP) library. This is a great library if you don't want to control the LEDs and buttons yourself. However, things can get very complicated if you do want to use BSP and control the LEDs and buttons yourself.

    First (and poor) solution: The BSP uses the pin definitions found in the header file pca10028.h. So what you can do is to change the pin defines here. E.g. change

    #define BSP_LED_0_MASK (1<<BSP_LED_0)
    

    to

    #define BSP_LED_0_MASK (1<<5)
    

    This should make pin 5 toggle instead of LED_1 (remember to configure pin 5 as an output). This is not a very smart way to do it though, as changing pca10028.h will affect all your examples and code located in the SDK because all of the examples read the definitions in this very header file. The BSP module will not work as intended either.

    Second (and better) solution: Make your own header file containing all the defines found in pca10028 and change the defines you need. Then use this file instead of the original. This solution will still affect the BSP module as well.

    Third (and maybe the best) solution: Remove all BSP related code in the example and make all the code yourself (maybe using the app_button library). This is the best way, but requires you to do some work on your own.

    Fourth (possible) solution: I don't have the time to do research on this solution, but it might be possible to use the BSP together with some PPI/GPIOTE code to make the blinking LED trigger an event that causes pin 5 toggle. Have a look at the example I posted in this relevant thread.

Reply
  • Hi

    First of all, the example is using the Button Support Package (BSP) library. This is a great library if you don't want to control the LEDs and buttons yourself. However, things can get very complicated if you do want to use BSP and control the LEDs and buttons yourself.

    First (and poor) solution: The BSP uses the pin definitions found in the header file pca10028.h. So what you can do is to change the pin defines here. E.g. change

    #define BSP_LED_0_MASK (1<<BSP_LED_0)
    

    to

    #define BSP_LED_0_MASK (1<<5)
    

    This should make pin 5 toggle instead of LED_1 (remember to configure pin 5 as an output). This is not a very smart way to do it though, as changing pca10028.h will affect all your examples and code located in the SDK because all of the examples read the definitions in this very header file. The BSP module will not work as intended either.

    Second (and better) solution: Make your own header file containing all the defines found in pca10028 and change the defines you need. Then use this file instead of the original. This solution will still affect the BSP module as well.

    Third (and maybe the best) solution: Remove all BSP related code in the example and make all the code yourself (maybe using the app_button library). This is the best way, but requires you to do some work on your own.

    Fourth (possible) solution: I don't have the time to do research on this solution, but it might be possible to use the BSP together with some PPI/GPIOTE code to make the blinking LED trigger an event that causes pin 5 toggle. Have a look at the example I posted in this relevant thread.

Children
No Data
Related