News for hackers. Stuff that matters.
Re:Switch bouncing reference traces for a variety of differe... by frudyputy on Sunday May 04, 2025 @05:59AM (#43885736)
This is a very trivial problem, it doesn't even feel right calling it a 'problem'. It's probably the second lesson for the greenest Arduino newbie, right after blinking an LED. Don't let it discourage you from embedded hardware.
Re:Switch bouncing reference traces for a variety of differe... by lambdaone on Sunday May 04, 2025 @06:31AM (#43885874)
Doing it right (via the algorithm above) is a trivial few lines of code. The thinking behind the state machine that gives both high reliability and low latency isn't trivial. It is, however, obvious once you know the trick of maintaining an extra auxiliary variable in addition to counter/timer variables, and understand that you don't need to wait for the bouncing to finish before registering a change. Think sort algorithms; everyone comes up with bubblesort first, but you can do much, much better with only tiny changes after a bit of thought.
Re:Switch bouncing reference traces for a variety of differe... by formerly_proven on Sunday May 04, 2025 @06:51AM (#43885962)
On the one hand yes on the other hand I’d boldly claim incorrect debouncing is the most common (and usually exceedingly obvious) defect in embedded systems.
Re:Switch bouncing reference traces for a variety of differe... by tonyarkles on Sunday May 04, 2025 @08:57AM (#43886455)
And yet… I’ve seen it done wrong so many times, resulting in either spurious inputs or lost inputs, depending on how it’s been implemented.

I agree with you, don’t let it discourage you from embedded hardware. If you want to be successful in the embedded space, though, this is a great easy example to show that you need to take into account a bunch of physical effects when you’re doing hardware. Capacitors change their value with temperature and applied voltage (!), resistors have capacitance and inductance (which may or may not matter), clock crystals change frequency with temperature, switches bounce, ADCs have sampling capacitors that need to charge, chips power themselves up from active-high TTL lines, etc.

I’ve been doing embedded for 20 years now and one of the biggest things I’ve encountered with new learners is that the Arduino platform is amazing for people to get into the field but they’ll hit a point where something mostly works and they don’t have the rest of the background necessary to debug or understand why it doesn’t work as well as they thought it would. Or works great and then “randomly” blows fuses/burns out of there isn’t a fuse.

Re:Switch bouncing reference traces for a variety of differe... by bombela on Sunday May 04, 2025 @02:49PM (#43888600)
So trivial that I want to throw away by the window my microwave everytime I use it!