RGB LED with button

Im currently trying to program a RGB LED to light up a certain color when a button is pressed. I would like to make each button light up a certain color on the LED. Im having trouble trying to find research on RGB LED's and buttons, I would like to have something to work off of like a schematic or code. Thanks ;)

This thread covers Common Anode RGB LED's with how to attach them and some code example: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228874758

This playground tutorial shows how to connect a button to the arduino and has some code showing how to debounce a button:http://www.arduino.cc/en/Tutorial/Debounce

Try both of the examples seperate and then work on combining the two. Thats the best way to learn.

[edit]Also note the example on RGB LED's I linked to is for common anode type. It will be a little different for common cathode type.[/edit]

Here is the code from a project i did. You have 6 buttons. 2 per color on the RBG. One brightens and the other dims.

/*
  RGB Color Wheel w/ Serial Comunication
  
  Indivigually control the brightness of each color in an RGB LED
  using 6 pushbuttons attached to pins 2 thru 7. The pushbuttons
  on the even number pins will brighten the corosponding
  LED and the odd numbered ones will dim them. RGB will be attached
  to pins 9, 10, and 11.
  
  The Circuit:
  * RGB LED with common anode on +5V
  * Red cathode connected to pin 9 threw 220 Ohm resistor
  * Blue cathode connected to pin 9 threw 470 Ohm resistor
  * Green cathode connected to pin 9 threw 1000 Ohm resistor
  * pushbutton 1 attached to pin 2 from ground
  * pushbutton 2 attached to pin 3 from ground
  * pushbutton 3 attached to pin 4 from ground
  * pushbutton 4 attached to pin 5 from ground
  * pushbutton 5 attached to pin 6 from ground
  * pushbutton 6 attached to pin 7 from ground
  
  If the RGB LED in use has a common cathode the the roles of the
  buttons become reversed and the brightness of the LED will be
  full on at the start of code.
  
  created 13 Jan 2010
  by digimike
  modified 16 jan 2010
  by digimike
  */
  
boolean ledpin[] = {9, 10, 11};  // assign LEDs to pins
    
boolean button[] = {2, 3, 4, 5, 6, 7};  // assign pushbuttons to pins
  
boolean buttonstate = 0;
    
int fadered = 255;    // starting brightness values for each led
int fadegreen = 255;  // 255 sets the LEDs to the off position
int fadeblue = 255;   // when an RGB with a common anode is in use

void setup ()
{    
  Serial.begin(9600); // designates serial comunication rate
  for(int x=0; x<6; x++)
  {
    pinMode(button[x], INPUT);  //initialize pushbutton pins as input:
  }
  for(int x=0; x<6; x++)
  {
    digitalWrite(button[x], HIGH);  // pushbuttons are read as high till pressed
  }
  analogWrite(ledpin[0], fadered);    //lights the LED at current brightness
  analogWrite(ledpin[1], fadegreen);    //lights the LED at current brightness
  analogWrite(ledpin[2], fadeblue);    //lights the LED at current brightness    
  }
  
void loop()
{
  for(int x=0; x<6; x++)
  {
    buttonstate = digitalRead(button[x]);    //check button state
    if(buttonstate == LOW && fadered >0 && button[x] == 2)
    {
      // if button is pressed increase brightness by 5
      fadered -=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
    
    if(buttonstate == LOW && fadered < 255 && button[x] == 3)
    {
      // if button is pressed decrease brightness by 5
      fadered +=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
    
    if (buttonstate == LOW && fadegreen > 0 && button[x] == 4)
    {
      // if button is pressed increase brightness by 5
      fadegreen -=5;
      analogWrite(ledpin[1], fadegreen);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }  
        
    if (buttonstate == LOW && fadegreen < 255 && button[x] == 5)
    {  
      // if button is pressed decrease brightness by 5
      fadegreen +=5;
      analogWrite(ledpin[1], fadegreen);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
    
    if (buttonstate == LOW && fadeblue > 0 && button[x] == 6)
    {  
      // if button is pressed increase brightness by 5
      fadeblue -= 5;
      analogWrite(ledpin[2], fadeblue);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
    
    if (buttonstate == LOW && fadeblue < 255 && button[x] == 7)
    {  
      // if button is pressed decrease brightness by 5
      fadeblue += 5;
      analogWrite(ledpin[2], fadeblue);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
    if(buttonstate == LOW)  // checks if any button has ben pressed
    {  // prints brightness levels to the PC. 0 being full on and 255 being off
      Serial.print("Red LED level is at: ");
      Serial.println(fadered);
      Serial.print("Green LED level is at: ");
      Serial.println(fadegreen);
      Serial.print("Blue LED level is at: ");
      Serial.println(fadeblue);
    }
  }
}

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263501476/0