Introduction: Fading RGB LED (Arduino)

In this Instructable I'm going to show you how to make a simple fading RGB Led.
It can be used as a nice night lamp or as mood lighting.

Step 1: Parts

To make it you'll need:
- an Arduino ( I'm using an Arduino UNO R3, but others may work aswell )
- an RGB Led ( I used a common anode one, common cathode will work too )
- a Breadboard
- some wire
- 2 resistors 180 ohm  ( Brown, Grey, Brown, Gold )
- 1 resistor 330 ohm ( Orange, Orange, Brown, Gold )

Step 2: Schematic

The schematic is very simple.
If you have a commone anode led (like i do) just connect it to +5v, if you have a common cathode led connect it to 0v.
Connect the 3 other leads to 3 PWM pins on your arduino with a resistor between (the value depends on the led).

Step 3: Code

The code is a little bit more difficult but still fairly simple.
This code only works for common anode leds.
If you want to use it for common cathode leds you'll have to change all  the "analogWrite( COLOR, 255 - colorVal );" lines to "analogWrite( COLOR, colorVal );" (without the "255 - "), then it should work (i didn't test it).

#define GREEN 3
#define BLUE 5
#define RED 6
#define delayTime 20

void setup() {

  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);
  digitalWrite(GREEN, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, HIGH);
}

int redVal;
int blueVal;
int greenVal;
 
void loop() {
 
  int redVal = 255;
  int blueVal = 0;
  int greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    greenVal += 1;
    redVal -= 1;
    analogWrite( GREEN, 255 - greenVal );
    analogWrite( RED, 255 - redVal );

    delay( delayTime );
  }
 
  redVal = 0;
  blueVal = 0;
  greenVal = 255;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal += 1;
    greenVal -= 1;
    analogWrite( BLUE, 255 - blueVal );
    analogWrite( GREEN, 255 - greenVal );

    delay( delayTime );
  }
 
  redVal = 0;
  blueVal = 255;
  greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    redVal += 1;
    blueVal -= 1;
    analogWrite( RED, 255 - redVal );
    analogWrite( BLUE, 255 - blueVal );

    delay( delayTime );
  }
}

Step 4: DONE !

Use your imagination to extend / modify / improve / ... the project.
Show your creations in the comments and please tell me what you think about this instructable, because it's my first one.
Also, Please correct me if I made any mistakes.