RGB LED Color Mixing on the Pico
So far your LEDs have each been a single fixed colour — a red one is always red, a green one is always green. But there is a magic little component called an RGB LED that can glow in any colour you can imagine: warm orange, sky cyan, hot magenta, pure white, or a slow rainbow that drifts through every shade. And it does this with just one LED package and three of your Pico's pins.
The secret is that an RGB LED is really three tiny LEDs in one shell — one red, one green, one blue. By using the PWM dimming trick you already learned to set each of those three to a different brightness, and letting their light blend together, you can mix millions of colours. This is exactly how the screen you are reading this on makes every colour it shows. In this lesson you will wire an RGB LED, write a friendly set_color(r, g, b) helper, and mix named colours, rainbows, and random flashes.
What you will learn
- What is really inside an RGB LED and why it has four legs.
- The difference between a common cathode and a common anode RGB LED — and the inverted logic trap that catches everyone.
- How to drive the three colours with three PWM channels, one per pin.
- How to build a
set_color(r, g, b)helper that maps the familiar 0–255 range onto the Pico'sduty_u16()values. - Additive colour mixing: the recipes for yellow, cyan, magenta, white and orange.
- How to make a smooth rainbow fade with loops, and flash random colours.
- Why each colour needs its own resistor, and why red behaves differently from green and blue.
- How to troubleshoot swapped pins, washed-out pale colours, and wiring mistakes.