Fading sequence with two PWM pins (at separate times)

I have a question regarding a Year 12 school project I am undertaking.

I have a blue LED plugged into a PWM pin (~11) and a green LED plugged into another PWM pin (~10).

I have managed to light up one LED in a fading sequence however I would like both to light up but at different times. And be able to control the time period between each one lighting up.

Any help would be appreciated!

Here is my code so far:

int led1 = 11;                 // blue LED
int led2 = 10;              // green LED
int brightness = 0;
int fadeAmount = 5;


void setup() {
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
}


void loop() {

 analogWrite(led1, brightness);

 brightness = brightness + fadeAmount;


 if (brightness == 0 || brightness == 255) {
   fadeAmount = -fadeAmount ;
 }

 delay(30);

}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

The basic idea is to use millis() to do anything timing related.

Have a look at the BlinkWithoutDelay example that comes with the IDE and Demonstration code for several things at the same time to get ideas.