RGB mood light
A common-cathode RGB LED on PWM pins 9, 10 and 11, fading through colours.

The code
// A common-cathode RGB LED: red on 9, green on 10, blue on 11 (all PWM).
// Each colour has its own resistor: 220 Ω for red, 100 Ω for green and blue (they drop more).
void color(int r, int g, int b) {
analogWrite(9, r);
analogWrite(10, g);
analogWrite(11, b);
}
void setup() {
}
void loop() {
for (int i = 0; i < 255; i += 3) { color(255 - i, i, 0); delay(15); }
for (int i = 0; i < 255; i += 3) { color(0, 255 - i, i); delay(15); }
for (int i = 0; i < 255; i += 3) { color(i, 0, 255 - i); delay(15); }
}


