Conceptual
Login

Non-Blocking Timing with millis()

delay() freezes the entire loop, so a sketch that must watch several sensors instead timestamps each task with millis() and acts when the elapsed interval has passed, using unsigned subtraction so the 49.7-day rollover is handled correctly. This turns the loop into a cooperative scheduler where every task runs briefly and returns.

This Concept is waiting for its first lesson!

delay() freezes the entire loop, so a sketch that must watch several sensors instead timestamps each task with millis() and acts when the elapsed interval has passed, using unsigned subtraction so the 49.7-day rollover is handled correctly. This turns the loop into a cooperative scheduler where every task runs briefly and returns.

Are you a teacher? Sign in to start contributing.

Sign In