Raspberry Pi practice problem · Buttons & input
Tap tempo
HardBudget $4Python · gpiozero
Musicians set a tempo by tapping it. A button on GPIO27 (to ground) and an LED on GPIO17.
- Collect taps. After 4 taps, the tempo period is the average gap between them; start blinking the LED with that period, half on, half off, starting with on.
- A gap of more than 2 s since the previous tap starts a new series (that tap is tap 1).
- The LED keeps blinking at the old tempo until a new series of 4 taps completes; before the first series it is off.
The test taps at 1.0, 1.6, 2.2 and 2.8 s (0.6 s period), then at 7.5, 7.9, 8.3 and 8.7 s (0.4 s period). Each tap lasts 0.1 s.