正常
Button Input: Debouncing, State Machines, and Type Safety
Buttons are harder than LEDs—hardware bounce, non-blocking debouncing, state machines, plus type-safe refactoring in C++.
Motivation
- Part 19: From Output to Input — Why buttons are harder than LEDs
Hardware Fundamentals
- Part 20: GPIO Input Mode Internal Circuits — How the chip "hears" external signals
- Part 21: Button Circuits and Mechanical Bounce — What real-world signals look like
HAL and Polling
- Part 22: HAL GPIO Input API — How to read button states in code
- Part 23: Polling Buttons in C — First hands-on: controlling an LED with a button
Debouncing
- Part 24: Non-blocking Debounce — Don't make the CPU wait
- Part 25: 7-State Debounce State Machine — The core of this series
C++ Refactoring Evolution
- Part 26: Refactoring Button Code with
enum class— Type-safe input - Part 27: Events +
std::variantDispatch — Type-safe "what happened" - Part 28: Button Template Class Design — Let the compiler do the work
- Part 29: Constraining Callbacks with Concepts — Complete code walkthrough
Interrupts and Summary
- Part 30: EXTI Interrupts — Pitfalls and exercises