Want to blink only 1 time? newbie question

I,

Today i received my arduino and was looking at the code of the blink led.

I thought I altered the code , to let it blink only one time.

I tested: { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin, HIGH); }

and: { digitalWrite(ledPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin, LOW); }

But it doesn't stop. Where is it going wrong?

I hope somebody can help me.

"loop()" will always repeat. If you want it to execute just once, put it in "setup()"

Yep that works :),

Thx alot.

Now it also work when i use “for (int x=0; x<10; x++)”
to let it blink 10 times :).
I was always putting it in loop()…

Put this in the setup

digitalWrite(ledPin, HIGH);   
delay(1000);
digitalWrite(ledPin, LOW);

Altered classical first example see last line in LOOP(), I think a more ARDUINO way ... I hope ;)

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

// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  while(1); //delay(1000);                  // wait for a second

Either way is ok -- if you put a closing brace } for loop() in the example just above. The important thing is that you learned quite a bit just with that simple example.

This way of doing it might make some sense in certain situations also. There are usually several ways to do most anything. Some might be more appropriate than others in some situations but the important thing is that the job gets done and you understand how.

int ledPin =  13;    // LED connected to digital pin 13
int alreadyBlinked = 0;
// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
      if(alreadyBlinked == 0)
      {
             digitalWrite(ledPin, HIGH);   // set the LED on
             delay(1000);                  // wait for a second
             digitalWrite(ledPin, LOW);    // set the LED off
             alreadyBlinked = 1;
       }
}