The secret life of switches

Post here to teach people how to do something.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Chuckt
I practically live here!
I practically live here!
Posts: 1127
Joined: Sun Mar 28, 2010 1:36 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

The secret life of switches

Post by Chuckt » Sat Apr 23, 2011 7:33 am

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.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: The secret life of switches

Post by bitfogav » Sat Apr 23, 2011 6:42 pm

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.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: The secret life of switches

Post by brad » Sat Apr 23, 2011 9:22 pm

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

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 5 guests