This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Debounce in callbacks

Hello!

I currently have an external button and LED connected to the Icarus IoT dev board. For the time being, I just want to turn on the LED in the callback function when I press the button. However, the button (and the board) is highly sensitive and registers several interrupts with one push. I can even turn on the LED by touching the pin with my finger!

So I was wondering if there is any easy way to add some kind of debounce code in the callback itself? I have seen some examples here and there, but none of them that is a really proper method nor being used inside the callback itself. 

Looking forward to seeing your suggestions!

Parents Reply Children
  • Hello again!

    Thank you for the response.

    I'm currently using the Icarus IoT dev board with the nRF9160 chip. I have already implemented the buttons.c, buttons_def.h, and the overlay. I'm curious if the led_state_def.h is necessary? I have not implemented it and is that why I get the error in the "module_set_state" function? This function is declared in the "module_state_event.h" file.

  • Hi Christian,

    I did not encounter this error after adding these files for the nrf9160dk_nrf9160_ns building with the original Common Application Framework preview sample.

    Did you make any changes?

    Best regards,

    Charlie

  • I do not recall making any changes except for changing the pin numbers that fits the board. Have you tried to compile the code for actinius_Icarus_ns? Since that's the board I'm using and not the nrf9160dk. Not sure if that makes any difference? 

  • Hi Christian, 

    This sample does not support actinius Icarus board and it also has big differences with our supported nRF DK boards, so it will take some effort to modify the sample to fit this board. 

    I suggest you either switch to nRF9160DK to continue the learning of CAF or just search "debounce code in c" to quickly catch some debouncing implementation for your application. The general theory is that on edge detection wait for several ms and detect edge again and if the change is still present then it is a true change. The button.c from CAF set debounce interval CAF_BUTTONS_DEBOUNCE_INTERVAL 2ms as default.

    Best regards,

    Charlie

  • Hello again, Charlie!

    Before I made this post I was looking around for some suitable debounce code. However, I found none that was implemented directly into the callback, hence this post. Is there a reason why I can't find any that suits my use?

Related