Menu
CoddyTech

Mix Colours of Light

Part of the Outputs section of Coddy's Arduino journey. Lesson 7 of 24.

When two colours of the RGB LED are on together, your eye sees them mixed into one. Light mixes differently from paint:

  • red and green make yellow
  • green and blue make cyan, a light blue
  • red and blue make magenta, a pink purple
  • all three make white

So every colour is three choices, one for each pin. Yellow is:

digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);

Write all three pins for every colour, even the ones that are off. A pin keeps its last value, so a colour left on from before would mix in.

challenge icon

Challenge

Easy

Show the mixed colours, one second each, in this order and again and again:

  1. yellow
  2. cyan
  3. magenta
  4. white

Write all three pins for every colour. Press Run, then Check.

Try it yourself

const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  // yellow
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);
  delay(1000);

  // then cyan, magenta and white
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Outputs

Practice on your own: Arduino playground