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

  • It always helps if you post code if you are having trouble making something work.

    But if I had to guess your problem, I would bet that you forgot to configure a pin as an output before trying to drive it.

    Look at the blinky example as the simplest possible piece of code and start there. Look at how they first configure the pin as an output. If that still does not help, try posting code.

  • Hello, David, thanks for your answer. I'm using ble_app_hrs_c example, I didn't wrote the code. The example works fine, but I cannot find where in the code I should edit to change led 1 from blinking to pin 5 toggling.

  • Hi

    I'm not sure if I understand what you want to do.

    1. Do you want to change the LED blinking on the Collector board (as it is referred to in the example documentation) that runs the ble_app_hrs_c example?

    2. Do you want to connect a sensor board and make a button push on the collector board toggle a LED on the sensor board?

    3. Do you use a sensor board? If so what code are you running on this board?

  • Hello, Martin. Thanks for the comment.

    1. Yes! But I don't know where in the code (file and code line) to do that - neither how, as input push button uses gpiote + app_button + app_timer layers and I'm uncertain how everything comes together...
    2. This could be usefull to my application, but I don't want to that now.
    3. Yes, sensor board = ble_app_hrs example. Sensor + Collector working fine in the boards.
  • 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.

Related