Fading Duration

Let’s say I was using some simple fade code like the example in Arduino:

int ledPin = 9;    // LED connected to digital pin 9

void setup()  { 
  // nothing happens in setup 
} 

void loop()  { 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 
}

What do I need to add to control how long the overall fade takes? Thank you.

int ledPin = 9;    // LED connected to digital pin 9
int fadeDelay = 30; //change this to control fade time

void setup()  {
  // nothing happens in setup
}

void loop()  {
  //you could change the fadeDelay if you want to dynamically change the fade time

  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for fadeDelay milliseconds to see the dimming effect    
    delay(fadeDelay);                            
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for fadeDelay milliseconds to see the dimming effect    
    delay(fadeDelay);                            
  }
}

Thank you sir!

I thought I tried that before and didn't get what I wanted....let me give it another go.

Is there a way to express the delay in minutes rather than milliseconds?

ms = minutes * 60 * 1000