Re: Another multiples LEDs blinking question

I also have a question..and I am a newbie...
I would like to modify the code below to use the 'blink without delay' or "millis()" type code to do the same thing as the code below.

I've been racking my brain for a week on this, any and all help would be appreciated.

int led = 13; // blink 'digital' pin 13 - AKA the built in red LED

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH);
delay(10);
digitalWrite(led, LOW);
delay(990);
}

Please note the delay times... for a strobe affect.

thanks Rocco

like this:

int led = 13;
unsigned long startTime;
unsigned long pulse = 10UL;
unsigned long interval = 1000UL;

void setup() 
{
  pinMode(led, OUTPUT);
}
//
void loop() 
{
  flash();
}

void flash()
{
  if (millis() - startTime < pulse)
  {
    digitalWrite(led, HIGH);
  }
  else if (millis() - startTime < interval)
  {
    digitalWrite(led, LOW);
  }
  else startTime += interval;
}

Thanks Bulldog!!! you make it look ez.
Now I need to learn what it all does, and I will.

Thanks again.

rocco34:
Thanks Bulldog!!! you make it look ez.
Now I need to learn what it all does, and I will.

Thanks again.

moderator: please split this thread

it is easy if you think about millis() as a timestamp:

assign the current time to startTime:

startTime = millis();

how much time has elapsed?

millis() - startTime = elapsedTime;

has my timer expired?

if millis()- startTime > interval;

then start the timer all over by adding the interval to the startTime:

else startTime += interval;

above is equivalent to :

else startTime = startTime + interval;

BulldogLowell:

rocco34:
it is easy if you think about millis() as a timestamp:

Thanks for laying it out, I get it now...
I needed to get the math right, and that "else if (millis() - startTime < interval)"
line... I was way off with my code.

Thanks

Rocco