Page 1 of 1

The secret life of switches

Posted: Sat Apr 23, 2011 7:33 am
by Chuckt
http://www.eetimes.com/discussion/break ... f-switches

When you open or close a switch, they sometimes touch multiple times and when you use high speed microcontrollers, sometimes you can get multiple results for the switch which could cause problems. This article gives you a little insight.

Re: The secret life of switches

Posted: Sat Apr 23, 2011 6:42 pm
by bitfogav
Thats very true, thats why when programming a microchip after a switch being pressed we had some code a bit like this:

Code: Select all

if button = pressed then
    // put your code here
    delayms(20)     //==== debounce delay for button
endif
Has you can see the delayms is the switch debounce delay.

Re: The secret life of switches

Posted: Sat Apr 23, 2011 9:22 pm
by brad
Or how about this one :D

Code: Select all

Sub CheckButton()
     If ButtonDebounce <> 0 then
          dec(ButtonDebounce)
     Else
          If ButtonPressed = true then
               ButtonDebounce = 10
               do this code here...
          Endif
     Endif
End Sub