Button Input and Pull Resistors
In the last lesson you told the Pico what to do by turning an LED on and off. Now we flip the direction: instead of the Pico talking to the world, it will listen to it. A push button is the simplest way for a human to send a signal into a microcontroller, and learning to read it correctly is the doorway to every keypad, sensor, switch and control you will ever build.
The big idea in one sentence
A digital input pin does not measure "is a button pressed?" — it measures voltage. It reports 1 when it sees a voltage near 3.3 V and 0 when it sees a voltage near 0 V. Your whole job when reading a button is to make sure the pin always sees one of those two clear voltages and never gets left "floating" in between.
What you will be able to do
- Configure a GPIO pin as a digital input with
Pin.IN. - Read the pin with
.value()and understand what0and1mean. - Explain the floating pin problem and why it makes buttons act possessed.
- Use the Pico's internal pull-up and pull-down resistors and wire a button for each.
- Toggle an LED on each press and count presses reliably.
- Understand button bounce and fix it with software debouncing.