PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Buttons & input

Pressed means high

EasyBudget $3Python · gpiozero

Most examples wire a button to ground with a pull-up, so pressed reads low. This time do it the other way round.

Build: a push button between GPIO27 and 3.3 V, and an LED (with a resistor) on GPIO17.

Program: use the Pi's internal pull-down so GPIO27 reads low at rest and high while pressed. The LED is on while the button is held.

The test presses the button at 1.0 s for 1 s and at 3.0 s for 0.5 s, and checks the level on GPIO27 as well as the LED.

Tip: Button(27, pull_up=False) turns on the pull-down.

More in Buttons & input