Go Down

Topic: trying to get led to blink 10 times, don't know what's wrong (Read 531 times) previous topic - next topic

peppermintt

const int LED = 13;
int count = 0;

void setup()
{
    pinMode (LED, OUTPUT);
   
 
   
}
void blinkLED(int timeOn, int timeOff, int numBlinks)
{
  for (count= 0; count <= numBlinks-1; count++)
  {
    digitalWrite(LED, HIGH);
    delay(timeOn);
    digitalWrite(LED, LOW);
    delay(timeOff);
  }
}

void loop()
{
 blinkLED(1000,1000,10);
}

Grumpy_Mike

Nothing wrong with that code it works.
Except of course it is not posted correctly, read How to use this forum

What is it doing that you don't want it to do?

Are you expecting it to stop after 10 blinks? No the loop function will repeat the blinks over and over.

peppermintt

It doesn't blink 10 times, it just keeps going and doesn't stop

Grumpy_Mike

Yes it will.
The loop function does just that it loops.

PaulRB

Move this line
Code: [Select]
blinkLED(1000,1000,10);
from loop() into setup()

Grumpy_Mike

Or add
Code: [Select]
while(1) { }
To the end of the loop function.

Go Up