Led Blinks for 10 seconds than stays ON

Hi there,
I would like to make a LED blinking for 10 seconds, then, after the blinking cycle, it should stay ON.

The sketch below works but I'm sure there is a more elegant way, probably using constexpr uint8_t NumberOfBlinks {*}.

Could you please guys give me a hint?
Thanks a lot

const int ledPin = 14;

void setup() {
 pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
     digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
      digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
      digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
      digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
   delay(1000); // wait for a second
   digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
   delay(1000); // wait for a second
      digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
}
  void loop() {}

Look into the concept of a "for" loop.

2 Likes

Is this functionality of blink LED 10 seconds then LEd shall stay on (forever)
all that you want to do in this project?

or

Do you plan to make theLED do more than just this?

const byte ledPin = LED_BUILTIN;        // 13

byte On = LOW;

void setup ()
{
    pinMode (ledPin, OUTPUT);
    for (int n = 20; n > 0; n--)  {
        digitalWrite (ledPin, ! digitalRead (ledPin));
        delay (250);
    }
    digitalWrite(ledPin, On);
}

void loop ()
{
}

It's just for that. I'll might use it for a project in the future.

Thanks a lot for the sketch.
It worked fine, I just replaced:

byte On = LOW;

with

byte On = HIGH;

so the LED stays on after the blinking cycle.

Much obliged!

hopefully you see that by defining what "On" is, instead of using LOW/HIGH makes things clear

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.