Exercise C: Debouncing (Stretch Goal)
~10 min
The Problem
If you've been pressing buttons, you may have noticed: sometimes a single press registers as multiple presses. This is called bounce — the mechanical contacts in the button vibrate when pressed, causing rapid on-off-on transitions.
What you expect: What actually happens:
HIGH ─────┐ HIGH ─────┐ ┌┐ ┌┐
│ │ ││ ││
LOW └────── LOW └─┘└─┘└──────
↑ press ↑ bounce!
Your interrupt fires on every edge — so a bouncy button triggers multiple interrupts for one press.
The Challenge
Add software debouncing to your interrupt-driven button. The idea: after detecting a press, ignore further interrupts for a short time (e.g., 50ms).
Approach: Timer-Based Debounce
You'll need a timer — another peripheral! Same pattern applies:
- Find the timer peripheral in esp-hal docs
- Create → Configure → Control — set up a timer
- Record the time of each interrupt; ignore interrupts that happen within the debounce window
Look for timer-related modules in esp-hal. The same Create → Configure → Control pattern applies:
- **Create:** How do you instantiate a timer?
- **Configure:** What resolution/frequency?
- **Control:** How do you read the current time?
No Hints
This is an advanced stretch goal. You'll need to navigate unfamiliar documentation (timers) and combine it with what you already know (interrupts). This is exactly the kind of problem-solving the workshop is designed to prepare you for.
If you solve it — congratulations, you've independently navigated a new peripheral using only the documentation. That's the skill that will serve you long after this workshop.