Switching fade from 1 LED to another with a switch (n00b question)

Hi all,

This is my sixth code, and the first one I can't seem to debug. I'd appreciate some feedback on this - when I run the code, there's no difference in the behaviors of the LEDs - they just fade together on one setting, or remain off on the other. headscratch

Thanks -

-FZ

int redPin = 11;
int bluePin = 6;
int redVal = 0;
int blueVal = 0;
int button = 7;
int rate = -1;



void setup (){
 pinMode (redPin, OUTPUT);
pinMode (bluePin, OUTPUT);
pinMode(button, INPUT); 

}

void loop (){
  digitalRead (button);
  if (digitalRead(button) ==HIGH){
  if (redVal >= 255){ 
 redVal = 0; 
}
else{
  redVal = redVal +1;
}
if (digitalRead (button) == HIGH){
  blueVal = blueVal +1;
}
if (blueVal >= 255){
 blueVal = 0; 
}
analogWrite(redPin, redVal);
analogWrite(bluePin, blueVal);
delay(20);
digitalRead(button);
}
//** int rate = -1
if (digitalRead (button) == LOW){
  if (redVal >= 255){
  rate=-1;
  {
   if (redVal<=0){
   rate = 1;
   } 
   redVal = redVal + rate;
  }
  
// digitalWrite(redPin, LOW);
 //digitalWrite( bluePin, LOW);
 //delay(20);
 //digitalRead(button);
}
}
}

Please, fix your formatting. It's no wonder you can't debug it - I can't follow it at all like that.

The red an blue values change the same way based on the same condition, so of course they are going to behave the same.

What are you trying to accomplish?

digitalRead(button);

If you are not concerned about the VALUE returned by the function, why do you bother to call the function?

fstopzero:
when I run the code, there's no difference in the behaviors of the LEDs - they just fade together on one setting, or remain off on the other.

Given that you only have one button, and it's controlling both LEDs in the same way, what else did you expect to happen? headscratch