Skip to main content

Section 2.1 Before Class: Switches, Pull-ups, and Bounce

In the previous chapter we drove GPIO pins HIGH and LOW from code. This reading is about the other direction: a GPIO pin configured as an input, where something outside the chip sets the voltage on the pin and your code reads it. A pushbutton is the simplest input device there is, and we’ll use one for the rest of the chapter, but getting a reliable reading out of one takes three things: how to read the voltage on a pin at all, how to give the pin a defined voltage while the button is not pressed, and what the switch’s metal contacts do in the few milliseconds while they close. The three subsections below take those in turn.