The Ball Rattles in the Cup Before It Counts
Land the tama in the big cup and watch closely: it doesn’t just arrive. It drops, taps the rim, hops, taps again, and then sits. Maybe forty milliseconds of chatter between contact and settled. My eye reads one catch. A fast enough sensor would read three.
Every mechanical switch does exactly this. Press a button and the two contacts don’t close once — they slap together, spring apart, close again, ringing down over a few milliseconds until the metal stops arguing with itself. A microcontroller polling at a megahertz sees a burst of on-off-on-off and, if you let it, faithfully registers four keypresses for your one. In the home-computer and early-embedded years this was a daily tax: keyboard matrices, arcade buttons, the reset line. The fix was cheap and everywhere, which is why it earned a name — debouncing.
The idea is stubbornness. Don’t trust a change until the signal holds still for a while. Sample the input; only accept a new state once you’ve seen it unchanged for N consecutive reads. Bounces get swallowed because they never stay put long enough to qualify.
var stable = false, count = 0
let need = 3
for s in [false, true, false, true, true, true, true] {
count = (s == stable) ? 0 : count + 1
if count >= need { stable = s; count = 0; print("settled: \(s)") }
}
The same stubbornness in Perl, which spent the ’80s and ’90s gluing exactly this kind of noisy input into something usable:
my ($stable, $count, $need) = (0, 0, 3);
for my $s (0, 1, 0, 1, 1, 1, 1) {
$count = ($s == $stable) ? 0 : $count + 1;
if ($count >= $need) { $stable = $s; $count = 0; print "settled: $s\n"; }
}
Both print settled exactly once for that rattly sequence. The lone 1 mid-stream — the ball’s first rim-tap — never survives to three, so it’s discarded. Only the run that holds counts.
need = 3 is the whole personality of the thing. Too low and a bounce sneaks through as a phantom catch. Too high and you add lag — the catch feels sluggish, registered late. Kendama players tune the same knob in their hands: bend the knees, drop the ken to meet the ball, absorb the arrival so it settles in one motion instead of chattering out of the cup. Soft hands are a mechanical debounce. The code just makes the waiting explicit.