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

Switching LED state using button in Blinky example

Hello,

I am playing around with the Blinky example on my custom board, where I have one button and two leds. Everything works fine and I can control the LED2 and detect the button action using the smartphone. 

What I would like to do now, is to change the led state not only via ble, but also using a single press of the button and have that notified to the smartphone.

For instance:

 - send 0x01 via smartphone -> LED ON        

 - press button -> LED OFF (notify the change in state 0x00)

 - press again the button -> LED ON (led state 0x01)

Any suggestion on how to do that??

Thanks in advance

Antonio

Parents
  • You need to do 4 things:

    1. Enable notifications on the LED characteristic 
      • This is done for the button characteristic, take a look at the function ble_lbs_init() in ble_bls.c to see how it is done
    2. Add a notify function for the LED characteristics
      • Take a look at the function ble_lbs_on_button_change() in ble_lbs_init() to see how this is done. This function notifies the Button characteristic
    3. Add your button to the array button[] in buttons_init() in main.c
      • E.g. YOUR_BUTTON (Set the define equal to whatever pin the button is connected to on your custom board)
    4. Add a new event for a button click
      • Inside button_event_handler() in main.c, add a new case with e.g. YOUR_BUTTON which will call the function made in step 2

    I have not tested this myself and may have forgotten something, but I believe this should work.

    Best regards,

    Simon

  • Thank you Simon!!

    I followed your points. It works perfectly Slight smile

Reply Children
Related