Saturday, 21 December 2013 22:21

Debouncing Multiple Switches

Written by
If you want to input a manual switch signal into a digital circuit you'll need to debounce the signal so a single press doesn't appear like multiple presses. 
 
There is a Bounce library for Arduino which is very easy to use. However there is limitations with this Bounce library.
  • You are unlikely to enable the internal pull-up resistor on switch pins, therefore each switch require an external pull-up resistor
  • It is not possible to detect the switch state before main loop (setup). When you press a switch during power on, you will never get the state of the switch.
 
 
Adafruit wrote an example code for multi-button checker with debouncing which will solve that two problems.
 
I'm modifying the example code, it is useful if you want something to only happen once when a button is pressed.

Read 39687 times Last modified on Sunday, 12 June 2016 11:42

4 comments

  • Comment Link admin Wednesday, 19 April 2017 15:21 posted by admin

    Hello, kinjobo:
    I may not understand your question. I think you need to declare a variable to hold your key press sequence inside the Loop()

  • Comment Link kinjobo Thursday, 13 April 2017 19:46 posted by kinjobo

    Hello..

    Thanks for sharing!

    How can I... lets say I press button 1, then button 2, then button 3, then button 6, then button 4,.....

    how can I set the button 6 can be recognized one more time?

    So buttons 1,2,3,4 will not be recognized but button 6 will be one more time??

    Thanks for help

  • Comment Link admin Sunday, 08 May 2016 12:14 posted by admin

    Each call to the check_switches() function will reset the button state, therefore it is not possible to detect multiple buttons at the same time.

    You should look for Bounce2 library https://github.com/thomasfredericks/Bounce2

  • Comment Link hadj Sunday, 08 May 2016 04:43 posted by hadj

    Hello,
    Thanks for sharing this!
    i've tried your function with three Catalex TTP223B capactive touch sensors, and it works great better than "justpressed[i]"

    I would like to press 2 sensors at the same time and call a function than, can you please advice me? how can i adapt your function?
    (i tried (thisSwitch == 0) && (thisSwitch == 1) but it doesn't work)

    Thank you for you help

Leave a comment

Back to Top