To use millis () for timing you need to record the time at which an action took place to start the timing period and then to check at frequent intervals whether the required period has elapsed. If so, you presumably want to do something, otherwise why would you be timing ?
The edge-detecting comparison of millis () is one way of handling it, but if you need coordination between multiple steps, using one or more variables (other than lineNumber within loop () and iteration of delay) to track and transition state across iterations of loop ().
Hello everyone, I’d like to share a simple and useful function for creating non-blocking delays in Arduino using millis(). This function allows you to perform tasks at specific intervals without blocking the rest of your code, unlike the delay() function. Here’s the code: // Variable to store the previous time in milliseconds unsigned long previousMillis = 0; // Function to check if the ...
Al final me he animado y he escrito un tutorial sobre millis. He intentado que sea comprensible y lo he hecho con ejemplos para que sea más fácil de entender. Dada la extensión del tema lo he divido en varias partes, así que disculpad, pero tardo un poco ponerlas todas. Allá vamos.
You're missing the point, using millis () correctly allows you to wait until the time is appropriate while freeing up the processor to do other things. Using while () like that you might as well just use delay (), you've just re-created delay () in a different way.
[SOLVED] How to correctly use millis () for delay - Arduino Forum