KEY TAKE AWAY POINTS:
Mind the 2+2 pins, and the internal connections
Usually as a simple digital signal input ("digital read pin [ ]")
Mind "floating input" and pull-up/down
START A BIT > Knowledge Base > This page
"digital read pin [ ]" reads in the input from pin (voltage), which must be safely managed. Idle input from pin (voltage) is floating, unless it's pulled up/down.
Use software to activate built-in pull up/down resistor, not always available.
Pull it up/down by a pulling-resistor wired externally.
A natural mechanical jitter phenomenon, for almost all contactors, including switch/button, or even just direct alligator clips contacts.
When closing the contacts, the contact bounces around a bit, going closed, open, closed, open, closed, etc. It's kind of like dropping a ball - it bounces before finally sitting still on the ground.
Hardware based approach
Software based approach
Just add a delay (“debouncing window”) after the initial detection, purposefully ignore the bouncing period
Micro:bit built-in button A/B input has 54ms denouncing period
More from Physical Computing