LED blink once then fade once and repeat.

Hi, I just got an experimental arduino kit and saw their tutorials on fade and blink.

Now, I was wondering how to code so the LED would blink once and then fade once and then repeat the same sequence. I tried to code something up but very quickly got lost ((

yea, just so you know what I tried was:

void setup() {                
  // initialize the digital pin as an output.
    pinMode(9, OUTPUT);     
}

void loop() {
  digitalWrite(9, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // set the LED off
  delay(1000);              // wait for a second
  
  // set the brightness of pin 9:
  analogWrite(9, brightness);    

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade: 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  // wait for 30 milliseconds to see the dimming effect    
  delay(30);             
}

I tried to code something up

If you don’t post your code, we can’t really help you.
Use the # icon on the editor toolbar.

I just did, and with that code, the LED just blinks it does not do the fade… :roll_eyes: Just to specify, I am a complete newbie ^^

You need to post all the code - I can't see where "brightness" is declared.

Remember, "loop" repeats, very, very quickly.

void loop() {
  digitalWrite(9, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // set the LED off
  delay(1000);              // wait for a second
  
  for (int brightness = 255;brightness >= 0; --brightness) {
    // set the brightness of pin 9:
    analogWrite(9, brightness);    

    // wait for 30 milliseconds to see the dimming effect    
    delay(30);             
  }

  delay (1000);
}

would be a start.

AWOL: You need to post all the code - I can't see where "brightness" is declared.

Remember, "loop" repeats, very, very quickly.

void loop() {
  digitalWrite(9, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // set the LED off
  delay(1000);              // wait for a second
  
  for (int brightness = 255;brightness >= 0; --brightness) {
    // set the brightness of pin 9:
    analogWrite(9, brightness);    

    // wait for 30 milliseconds to see the dimming effect        delay(30);                }

  delay (1000); }



would be a start.

Could you pleae, if you have time, explain to me the whole for () thing...if you dont mind.

http://arduino.cc/en/Reference/For

Thank you so much!