user35398: I have two LEDs an I want the first one getting linear brighter and the second one do the exact same thing just one ore two seconds later. When one LED has reached 100, it should getting darker until there's no light and then start again from the beginning. I#m trying now for quite a long time but couldn't get it going.
int LED = 11;
int LED2 = 10;
void setup() {

Serial.begin(9600);
}
int x;
int x2;
void loop() {

for(x = 0; x<=100;x++) 
{
while(x > 30)
{
for(x2 = 0; x2<=100;x2++)
{
analogWrite(LED2,x2);
delay(100); 
}
}

analogWrite(LED,x);
delay(100);
Serial.println(x);

}
}

I just wanted to do the beginning but it isn't working. Can somebody pleas help me?

user-1: Note: I think you will need to adjust the timings.
Hope this help:
int LED = 11;
int LED2 = 10;

unsigned long start;

int lum = 0;  // Light level LED
int step = 1;
int lum2 = 0; // Light level LED2
int step2 = 1;

void setup() {
  Serial.begin(9600);
  start = millis();
}

void loop() {
  unsigned long now = millis();

  if (now % 100 == 0) {
    // Every 100 ms, light goes up/down 1 notch.
    light(LED, &lum, &step);

    if (now - start > 2000) {
      //  Time to start with LED2
      light(LED2, &lum2, &step2);
    }
  }
}

/*
 * Light up/down one notch on a pin.
 */
void light(int pin, int* p_lum, int* p_step) {
  analogWrite(pin, *p_lum);  
  *p_lum += *p_step;

  if (*p_lum == 100) {
    *p_step = -1;
  }
  if (*p_lum == 0) {
    *p_step = 1;
  }
}


35398: <p>I have two LEDs an I want the first one getting linear brighter and the second one do the exact same thing just one ore two seconds later. When one LED has reached 100, it should getting darker until there's no light and then start again from the beginning. I#m trying now for quite a long time but couldn't get it going.</p>

<pre><code>int LED = 11;
int LED2 = 10;
void setup() {

Serial.begin(9600);
}
int x;
int x2;
void loop() {

for(x = 0; x&lt;=100;x++) 
{
while(x &gt; 30)
{
for(x2 = 0; x2&lt;=100;x2++)
{
analogWrite(LED2,x2);
delay(100); 
}
}

analogWrite(LED,x);
delay(100);
Serial.println(x);

}
}
</code></pre>

<p>I just wanted to do the beginning but it isn't working. Can somebody pleas help me?</p>
 -1: <p>Note: I think you will need to adjust the timings.</p>

<p>Hope this help:</p>

<pre><code>int LED = 11;
int LED2 = 10;

unsigned long start;

int lum = 0;  // Light level LED
int step = 1;
int lum2 = 0; // Light level LED2
int step2 = 1;

void setup() {
  Serial.begin(9600);
  start = millis();
}

void loop() {
  unsigned long now = millis();

  if (now % 100 == 0) {
    // Every 100 ms, light goes up/down 1 notch.
    light(LED, &amp;lum, &amp;step);

    if (now - start &gt; 2000) {
      //  Time to start with LED2
      light(LED2, &amp;lum2, &amp;step2);
    }
  }
}

/*
 * Light up/down one notch on a pin.
 */
void light(int pin, int* p_lum, int* p_step) {
  analogWrite(pin, *p_lum);  
  *p_lum += *p_step;

  if (*p_lum == 100) {
    *p_step = -1;
  }
  if (*p_lum == 0) {
    *p_step = 1;
  }
}
</code></pre>
