2 min read · Automation

delay stops the sketch's flow at the point where it is called, which can leave the program unable to respond to a button or read incoming data in time. Using elapsed time together with a state machine lets the loop come back and check several jobs. But it does not create parallel execution, and it does not meet a deadline by itself. Long-running work inside a library still has to be checked separately.
What this teaches and the order of experiments
- Separate the jobs of blinking an LED, reading a button and sending data, and give each job its own time interval.
- Calculate the time difference as an unsigned value of a suitable type, to handle the counter wrapping around.
- Build the states IDLE, RUN and ERROR, and make the conditions for changing state visible.
- Measure the loop time under real communication traffic, and set a timeout at every point that could wait.
Exercise and example applications
Exercise: write a simulation program that reads a button, switches a light in two stages, and sends the status over Serial, so that the button can be pressed while the light is running.
Limits and what else to check
millis cannot replace interrupts, timers or an RTOS in every case. If you need a very short response time, design for it and measure it separately. Do not move this logic into control of a real load while skipping system checks.
Manufacturer documents to read
- Arduino Hardware
- Arduino IDE documentation
References
- Arduino Hardware (accessed 2026-11-21)
- Arduino IDE documentation (accessed 2026-11-21)




