Back

Bonus Project: RGB Color Mixing

Difficulty  

Optional — Extra Credit

divider

What This Is

One LED, three colors inside it, and every shade in between. Mix them with three knobs, or cycle them in code.

This is the shortest project on the list and the one that explains something the rest of the unit never gets to: how a screen makes colors. Three channels, and brightness is just PWM.

divider

What You'll Need

  • The tricolor RGB LED, with a resistor on each of its three color legs
  • Three free GPIO pins — any three you are not using
  • Optional: the potentiometer, if you want to mix by hand

An RGB LED is really three LEDs sharing one package and one common leg. Find out whether yours is common cathode (the shared leg goes to GND) or common anode (it goes to 3V3) before you wire it — on a common anode part, a higher duty makes it dimmer.

divider

Build It

  1. Light one color at a time. Red on its own, then green, then blue. Confirm which leg is which.
  2. Dim one channel with PWM duty, the same way you set motor power in Activity 2.12.
  3. Write set_color(r, g, b) taking three brightness values, so the rest of your program thinks in colors rather than pins.
  4. Make the secondary colors. Red plus green is yellow, green plus blue is cyan, all three is white. Check them against a screen if you like.
  5. Fade between two colors smoothly, rather than jumping.
divider

Then Make It Yours

  • Use the knob to sweep through the rainbow
  • Show temperature as a color instead of a bar — blue when cool, red when warm
  • Fade the onboard RGB LED on GPIO 3 the same way and compare
  • Use it as the rover's team color in the Sumo tournament

Commence Project