Raspberry Pi practice problem · LEDs & PWM
Fuel gauge
MediumBudget $7Python · gpiozero
A plain bar graph jumps from LED to LED. A smoother gauge lights the full LEDs fully and the next one partly.
Four LEDs, bottom to top: GPIO5, GPIO6, GPIO13, GPIO19. For a level v from 0 to 1, LED number i (0 = bottom) gets the duty v × 4 − i, clipped to 0…1. So 0.6 means 1, 1, 0.4, 0.
Show the levels:
- 0.6 from 0 to 1 s
- 0.3 from 1 to 2 s
- 0.9 from 2 s on, and stay there
Tip: LEDBarGraph(5, 6, 13, 19, pwm=True) does exactly this for its value.