PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Buttons & input

Ready, set, go

EasyBudget $3Python · gpiozero

Not every program needs callbacks: sometimes it should simply wait for a person.

A button on GPIO27 (to ground) and an LED on GPIO17. The program:

  1. prints Waiting... straight away
  2. waits until the button is pressed
  3. prints Go! once and switches the LED on for good

Later presses change nothing. The test presses the button at 2.0 s and again at 3.5 s.

Tip: gpiozero's button.wait_for_press() blocks until the press.

More in Buttons & input