Alternate to delay(), HOLD LED state for some time

Hello,
I want to know that if there is an alternate to delay. I want to hold the LED On for 5 seconds and then then turned that led on and make other LED On. Simple i want to hold the state of an LED for some time.
What would be the best way without using delay.
Thanks

Timeout timer.

Pete.

how to use that is it fit in this situation ?

BLYNK_WRITE(V5)
{   
int value = param.asInt(); // Get value as integer

if (value == 1)
  {
   digitalWrite(pin, HIGH);
   timer.setTimeout(5000L, []() {  
   digitalWrite(pin, LOW);
     });  
  }
}

i have found that code can you please explain it?

  • List item

@miannauman please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

The IF checks the state that was sent from BLYNK. If the check is true it does a digital write low. Then it starts a timer to wait for 5 seconds before it triggers high. But if you test it I think you will find it clear enough.

1 Like

This is exactly what I was going to say.