PyRaspBeta

← All practice problems

Raspberry Pi practice problem · LEDs & PWM

Theatre chase

MediumBudget $10Python · gpiozero

Six LEDs in a row, left to right: GPIO5, GPIO6, GPIO13, GPIO19, GPIO26, GPIO21. Light every third LED and march the pattern to the right, one place every 0.4 s:

timelit
0–0.4 s1st and 4th (GPIO5, GPIO19)
0.4–0.8 s2nd and 5th (GPIO6, GPIO26)
0.8–1.2 s3rd and 6th (GPIO13, GPIO21)

Then back to the 1st and 4th at 1.2 s, and so on forever. All other LEDs are off.

Tip: LEDBoard(5, 6, 13, 19, 26, 21) lets you set all six at once with board.value = (1, 0, 0, 1, 0, 0).

More in LEDs & PWM