fading out LED when 2. LED reaches certain value

Hi,

I am trying to fade out 2 LEDS. I want N°2 to start fanding out as soon as N° 1 reaches a certain value.

here is my function that isnt working:

void fading(){
  
  int max1=0;

  
   for(int i = 255; i >= 0; i--){  //fade out 1st LED
      analogWrite(led1,i);
      delay(10);
      max1=i;
      Serial.println(max1);
   }

//I know I can't get to max1 outside the loop, thats why its not working
   
   if(max1==128){  
        for(int i = 255; i >= 0; i--){  //fade out 2nd LED
          analogWrite(led2, i);
          delay(10);
        }
      }
}

does anyone have a solution?

thanks for any help

void fading(){
  
  int max1=0;

  
   for(int i = 255; i >= 0; i--){  //fade out 1st LED
      analogWrite(led1,i);
      delay(10);
      max1=i;
      Serial.println(max1);
//I know I can't get to max1 outside the loop, thats why its not working
//Why not move it then ? :)
  
   if(max1==128){  
        for(int i = 255; i >= 0; i--){  //fade out 2nd LED
          analogWrite(led2, i);
          delay(10);
        }
      }
   }
}

?

thats the function for the fading.

Sorry, here is the complete code.

#define LED1 11
#define LED2 10
#define BUTTON 13

int val = 0;
int oldVal = 0;
int state = 0;

void  setup(){

    pinMode(LED1,OUTPUT);
    pinMode(LED2,OUTPUT);
  
    pinMode(BUTTON,INPUT);
    Serial.begin(9600);
}

void loop(){
  val = digitalRead(BUTTON);

  //Serial.println(val);

  if((val==HIGH)&&(oldVal==LOW)){
    state=1-state;
    delay(10);
  }

  oldVal=val;

  if(state==1){

     digitalWrite(LED1,HIGH);
     digitalWrite(LED1,HIGH);
    
    delay(3000);
    fading(); 


    state=0;

  }
  else{
    
      digitalWrite(LED1,LOW);
      digitalWrite(LED1,LOW);
    }
}

void fading(){
  
  int max1=0;

  
   for(int i = 255; i >= 0; i--){  //fade out 1st LED
      analogWrite(LED1,i);
      delay(10);
      max1=i;
      Serial.println(max1);
   }

//I know I can't get to max1 outside the loop, thats why its not working
  
   if(max1==128){  
        for(int i = 255; i >= 0; i--){  //fade out 2nd LED
          analogWrite(LED2, i);
          delay(10);
        }
      }
}

oh sorry you actually changed my code. I haven't seen it. Unfortuantely this isn't working the way I want.

Now LED N°1 is fading to 128 and stops --> LED N°2 is fading to 0 -->LED N°1 continues fading to 0.

I don't want LED N°1 to stop fading. I want both LED to fade out at different Intervals.