Skip to main content
Yçalı.1
Visitor II
October 9, 2020
Question

hello I am developing an application that does led control with a button, I use a counter for this, but every time I hold the button, the counter increases more than 1

  • October 9, 2020
  • 1 reply
  • 573 views

So even if I hold the button down, I want it to increase once.

This topic has been closed for replies.

1 reply

Peter BENSCH
ST Technical Moderator
October 9, 2020

Maybe you should debounce the button, as mechanical buttons bounce, i.e. may create more than one pulse per button press.

There are several techniques to do that, one of the easiest is to connect some small capacitor in parallel to the button, which together with the pull resistor forms some low pass filter. The time constant of that filter should be slightly lower than the period of the maximum speed to press that button (e.g. 100..200ms). You will find this solution also at the NUCLEO or DISCOVERY boards.

Good luck!

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.