PyRaspBeta

← All practice problems

Raspberry Pi practice problem · LEDs & PWM

Web colours

MediumBudget $4Python · gpiozero

Web pages write colours as hex codes: #RRGGBB, each channel a byte from 00 to FF. Duty = byte / 255.

An RGB LED (common cathode): red on GPIO17, green on GPIO27, blue on GPIO22, each through its own resistor. Show these colours one per second, starting at 0 s, and loop:

  1. #FF8000 (orange)
  2. #8000FF (violet)
  3. #00FF40 (spring green)

The test reads each pin's PWM duty (±0.02): e.g. orange is red 1.0, green 0.50, blue 0.

Tip: int("80", 16) is 128. gpiozero's RGBLED uses PWM by default.

More in LEDs & PWM