Raspberry Pi practice problem · Buttons & input
Short or long
MediumBudget $3Python · gpiozero
One button, two meanings. A button on GPIO27 (to ground):
- held for 1 s: print
Longas soon as the second is up, while it is still held — and nothing when it is released - released before 1 s: print
Shorton release
The test presses for 0.3 s at 1.0 s, for 2.0 s at 2.5 s, and for 0.8 s at 5.5 s.
Tip: Button(..., hold_time=1) with when_held and when_released, plus a flag to remember that the press was long.