PyRaspBeta

← All practice problems

Raspberry Pi practice problem · LEDs & PWM

Crossfade

MediumBudget $4Python · gpiozero

Two PWM LEDs, A on GPIO12 and B on GPIO13, hand the light over smoothly:

  • from 0 to 2 s, A fades evenly from full to off while B fades from off to full
  • from 2 to 4 s, they swap back (A up, B down)
  • repeat every 4 s

At any moment the two duties add up to 1: at 1 s both are at 50 %, at 2 s A is off and B is full. The test allows ±0.1 around the ideal values.

Tip: use small steps, e.g. 50 steps of 0.04 s per direction, and set b.value = 1 - a.value.

More in LEDs & PWM