How to blink one LED with Two time intervals using Millis()

Hi i need to blink led with two time interval using millis() function. the led blink like aeroplane blink its LED.
see the below code written in delay() function.
int led=13;

void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(50);
digitalWrite(led, LOW);
delay(50);

digitalWrite(led, HIGH);
delay(50);
digitalWrite(led, LOW);
delay(1000);
}

Pls convert this code to mills() function instead of delay().

t_tuku:
Pls convert this code to mills() function instead of delay().

We will be happy to help you - but you must do the work. Otherwise you learn nothing.

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

Se how far you get based on that information. If you get stuck please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. That way we can focus on the parts you need help with rather than wasting time on things that you can do.

...R

See How to blink multiple LED at different frequency without using delay()

My tutorial on How to write Timers and Delays in Arduino covers replacing delays with millisDelay timers.

There are a number of ways to do what you want.

The more general one is to define an unsigned long array of the times
unsigned long times[4] = {50, 50, 50, 1000};
/// led on, off, on, off,

Define a millisDelay timer and an index into the array.
starting at index 0, i.e. the 50.
start the millisDelay timer with this value times[index]
when the timer times out toggle the led and increment the index
loop the index back to zero if the increment == 4.
start the timer again with the next value in the array,

Using an array make it easy to modify the times and add more if needed.

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