Skip to main content

Difference Between delay() and a while Loop with millis() in Arduino?

What are the practical differences between using delay() versus a while loop with millis() for timing in Arduino projects? I assumed both methods are blocking, but I'm not completely sure.

Example using a while loop:

unsigned long start = millis();
while (millis() - start <= interval) {
    DoSomething();
}

Example using delay():

StartSomething();
delay(interval);
StopSomething();

How do these methods compare in terms of blocking behavior, responsiveness, and potential trade-offs?

Luigi
  • 181
  • 7