PyRaspBeta

← All practice problems

Raspberry Pi practice problem · LEDs & PWM

Peak meter

HardBudget $8Python · gpiozero

Audio meters show the level as a bar and a single peak dot that remembers the recent maximum, so short spikes stay visible.

Five LEDs, bottom to top: GPIO5, GPIO6, GPIO13, GPIO19, GPIO26. Play this list, one level every 0.5 s starting at 0 s:

LEVELS = [3, 5, 2, 1, 1, 4, 0, 0, 0]

At each step:

  • the bar: the bottom level LEDs are lit
  • the peak: peak = max of the current level and the two levels before it; if peak > 0, LED number peak (1 = bottom) is lit as well

After the last level (from 4.5 s) everything stays off.

For example at step 2 (level 2, recent levels 3, 5, 2) the bottom two LEDs and the top LED are lit.

More in LEDs & PWM