ONE BUTTON TWO FUNCTIONS ? LED HELP!!

/* this example is from Getting Started With Arduino
modified to my taste.
so far the LEDs are turning on and off with BUTTON7
and fading with two more BUTTONS up or down */

/* What I want to do is:
change colors with the same two BUTTONS up and down, but i don’t know how*/

#define REDPIN 3    //  LED pins 
#define GREENPIN 5 
#define BLUEPIN 6
#define BUTTON 2  brightness--      // the input pins where the 
#define BUTTON 4  brightness++      // pushbutton are connected 
#define BUTTON 7 on/of    

int val = 0;        // val will be used to store the state of the input pin
 
int old_val = 0;    // this variable stores the previous value of "val"

int state = 0;      // 0 = LED off and 1 = LED on

int brightness = 127;    // how bright the LED is, stores the brigthness value

unsigned long startTime = 0;  // when did we begin pressing?

void setup() 
{ 
  pinMode(3, OUTPUT);     //tell Arduino LED 3,5,6 
  pinMode(5, OUTPUT);     // are outputs          
  pinMode(6, OUTPUT);               
  pinMode(7, INPUT);      // and BOTTOMs 7,4,2  
  pinMode(4, INPUT);      // are inputs
  pinMode(2, INPUT); 
}

void loop()
{ 
  val = digitalRead(7);  // read input value and store it // yum, fresh
 
 delay(10);           //de-bouncing delay, it works better 
                      //with this than the second de-bouncing delay alone
                      
// check if there was a transition 
if ((val == HIGH) && (old_val == LOW))
{
      state = 1 - state;    // change the stae from off to on or vice-versa

  startTime = millis(); // millis() is the Arduino clock
                        // it returns how many millis have passed
                        // since the board has been reset.
                        // remember when the button was last pressed
 
 delay(10);       //second de-bouncing delay
}
 


/* here I want the LEDs change colors using the same
  two fading BUTTONS, is that possible?
  
 if( digitalRead(2) == HIGH) // change to red color 
 {
  analogWrite(3, 255);   // turns the LED on
  analogWrite(5, 0);    // turns the LED off
  analogWrite(6, 0);
 }
  if (digitalRead(2) == HIGH)      //if pressed again change to a different color
  {                                
  analogWrite(3, 0);   // turns the LED off
  analogWrite(5, 255);    // turns the LED on
  analogWrite(6, 0);
 }   */
 


  // This part of the sketch is working fine

 //checkwhether the button is being held down
 if((digitalRead(4) == HIGH) && (digitalRead(2) == LOW))
 {
   // if the button is held for more than 500ms.
   if (state == 1 && (millis() - startTime) > 500)
 
   brightness++;     //increment brightness by 1
   delay (0);        // delay to avoid brightness going up too fast
                     // 0 means fast and avobe 0 the LEDs fade slowly
 
    if(brightness > 255)     //255 is the max brightness
 
     brightness = 255;       // stays at 255
 }  
   //checkwhether the button is being held down
   if ((digitalRead(4) == LOW) && (digitalRead(2) == HIGH))  
   
  {
    // if the button is held for more than 500ms.
   if (state == 1 && (millis() - startTime) > 500)
 
    brightness--;      // decrement brightness by 1
    delay (0);         // delay to avoid brightness going down too fast    
                       // 0 means fast and avobe 0 the LEDs fade slowly
                       
     if(brightness < 5)     // 5 minimun brightness stablish 
    
      brightness = 5;       // stays at 5
    }                 

   
 
  old_val = val;         // val is now old, let's store it
  if (state == 1) 
{ 
  analogWrite(3, brightness);    // turn LEDs ON at the current brightnes level
  analogWrite(5, brightness);
  analogWrite(6, brightness);
} 
else 
{ 
  analogWrite(3,0);  //this part of the program makes the LEDs
  analogWrite(5,0);  //SHUT OFF when pressing the BUTTON 7
  analogWrite(6,0);  
}
}
/code]

One way to go about this would be with a color state array, and the index for the array counts up or down with the short press of your two buttons. Something like:

int ledPins[] = {3,5,6}; //red, green, blue pins
int colorArray[][] = {
                             {0, 0, 0},  //all colors off
                             {1, 0, 0},  //just red on
                             {0, 1, 1},  //green and blue on
                             {1, 1, 1}   //all colors on... etc.  Add all the state you want
                             };
int colorState;  //variable that changes value from 0 to # of states when button pressed
.
.
.
//All kinds of code
.
.
.
for(int i=0; i<3; i++){
   if(colorArray[colorState][i]) analogWrite(ledPins[i],brightness); 
   else analogWrite(ledPins[i], 0);
}
 //if colorState ==1, for instance, the above would turn on Red and turn off blue and green

I’m not sure if I have the syntax just right for a 2D array (it’s been awhile), but hopefully you get the idea of how it would be done.

why not look at using an on/off ic? used normally for power, but you might be able to factor it in
http://www.newark.com/digital-power

#define BUTTON 2  brightness--      // the input pins where the

Everywhere in the code that "BUTTON" appears, except this statement, of course, it will be replaced with "2 brightness--". Is that even remotely what you want?

  pinMode(3, OUTPUT);     //tell Arduino LED 3,5,6 
  pinMode(5, OUTPUT);     // are outputs          
  pinMode(6, OUTPUT);               
  pinMode(7, INPUT);      // and BOTTOMs 7,4,2  
  pinMode(4, INPUT);      // are inputs
  pinMode(2, INPUT);

So, the #defines were just a waste of time...

/* here I want the LEDs change colors using the same two fading BUTTONS, is that possible?

In my experience, verifying and uploading a sketch, and observing the results, is quicker and more satisfying than posting on a forum.

Your mileage may vary.