Using blinkWIthoutDelay on different times

Hey All,

I'm trying to get some code to work on an led so that it will blink twice, then delay. The code that I have gotten to work with using delay() is as follows.

digitalWrite(FastStrobe, HIGH);
digitalWrite(FastStrobe, LOW);
digitalWrite(FastStrobe, HIGH);
digitalWrite(FastStrobe, LOW);

However, that is of course throwing the rest of my code into weirdness because of the delay.

I have found other code online that suggest how to do it at a regular interval and it works great if I want to do simple on and off behavior.

void loop {


  unsigned long SScurrenttime = millis();  //  Assign a variable by the system time
  if (SScurrenttime - prem_SlowStrobe >= timer_SlowStrobe) {
  prem_SlowStrobe = SScurrenttime;

void toggleSlowStrobes() {
  ledS_SlowStrobe = (ledS_SlowStrobe == HIGH) ? LOW : HIGH;
  digitalWrite(SlowStrobe, ledS_SlowStrobe);

Any advise would be appreciated on how to do this without using delay.

You’re going the right way.
Persist and think.

You need a state-machine, or at the very least an array of delay times and an index into it.

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.


or in a couple of lines, something like :

loop() {
. . .
   int mPos = millis() % 1000  ;
   digitalWrite( fastStrobe , ( mPos < 150 || ( mPos > 350 && mPos < 500 ) ? HIGH : LOW ) ) ;
. . .

You may encounter some jitter once every approx. 50 days when millis() rolls over.