On and Off LED for only one time without delay() code

Dear all,
Can you please give me the suggestion code to blink the LED for only one time which doesn't use

delay()? I have tried searching the net and what I could ultimately find is the code to blink the LED

continuously without delay(). My purpose is to control the LED to "ON" and make it "OFF" after certain

amount of time. I cannot put delay() in my application. I would really appreciate if someone could help me

out.

I am looking forward to your suggestions.

Thanks. :slight_smile:

Is this for school?

"flag and start" are normally false.
lastMillis is unsigned long
start and flag are boolean
When you are ready to turn on the LED cycle, make start = true.

if(start == true)  // do we want to start the LED on/off cycle?
{
   lastMillis = millis(); // initialize the timing 
   digitalWrite( myLED, HIGH); // turn LED on
   start = false; // this prevents reinitializing lastMillis
   flag = true;   // this enables the timing checking
}


if(flag == true && millis() - lastMillis >= 1000UL) // if we in in checking mode, has the time expired?
{
   digitalWrite(myLED, LOW);  // turn led off
   flag = false; // this disables timing checking
}