One bulb, three colours inside, millions of mixes. Today you paint with light.
Enter the access code from the card inside your Beginner Kit (or from your GAMERIFT order email). Your name appears on every page and printout as the licensee.
Don't have a kit yet? Get the Beginner Kit, the code ships inside. Lost your code? Contact us with your order number.
Lean in close to a TV (not too close) and every white pixel is secretly three tiny lamps: red, green and blue. Mix them in different strengths and you get every colour a screen can show. Your kit has one of these three-in-one lamps, the RGB LED, and after last lesson you already know the dimming trick. Three PWM pins, three colours, infinite mixes. Today you build a lamp that can be any colour you want.
Time: 45–60 minutes · Difficulty: 2/5 · You need: Lesson 04 done (PWM is the whole trick here).
The RGB LED is three LEDs sharing one roof. Three of the legs are the red, green and blue inputs. The longest leg is the shared ground (the "common cathode"), everything flows out through it. Hold the LED with the longest leg second from the left: the legs read red, ground, green, blue.
You could write three analogWrite lines every time you want a colour. Or you could teach the board a new word, setColor(r, g, b), and say it once. A function is exactly that: a recipe you name, then reuse. Big programs are just hundreds of small recipes calling each other.
Unplug the USB. Push the RGB LED's four legs into four separate breadboard rows. Longest leg second from the left.
| From | To | Why |
|---|---|---|
| R3 pin 9 (~) | Resistor → RED leg (leftmost) | Red channel, dimmable |
| R3 pin 10 (~) | Resistor → GREEN leg (third) | Green channel, dimmable |
| R3 pin 11 (~) | Resistor → BLUE leg (rightmost) | Blue channel, dimmable |
| Longest leg (second) | R3 GND | The shared drain for all three |
Three resistors, not one. Each colour needs its own bodyguard because each is its own LED.
// GAMERIFT Beginner Kit, Lesson 05: Rainbow Maker // Teach the board a new word: setColor. const int redPin = 9; const int greenPin = 10; const int bluePin = 11; void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); } // Our new recipe: three strengths in, one colour out. void setColor(int r, int g, int b) { analogWrite(redPin, r); analogWrite(greenPin, g); analogWrite(bluePin, b); } void loop() { setColor(255, 0, 0); // pure red delay(800); setColor(0, 255, 0); // pure green delay(800); setColor(0, 0, 255); // pure blue delay(800); setColor(255, 120, 0); // orange, a mix! delay(800); setColor(150, 0, 200); // purple delay(800); setColor(255, 255, 255);// all three: white-ish delay(800); }
Film 15 seconds of your best colour creation for your lesson log. Stuck? Send a photo of your wiring via contact us.
So far you control the light. Next lesson the room controls it: a sensor that feels darkness arrive and switches your lamp on by itself. Your first automatic machine.