Millis during for/while loop

Hi forum. I'm a beginner and I just learned millis don't keep reading/ updating during a while loop.

I wonder, can't I just write a line of code within the while loop to keep reading and storing the millis value in my variable?

Does millis have the same issue during the for loop?

How can I keep making use of millis and read and store the value in my variable during while and for loop? - thank you guys!!!

Read again.... it does.

(It's not updated while interruptions are blocked).

You should give us a bit more context on what you want to achieve.

millis updates everywhere in your main thread as long as interrupts are enabled. It won't update during an interrupt (at least with the AVR core).

What happened when you tried?

1 Like

or read elsewhere. In the beginning, there may be as much call for unlearning stuff as there is for learning, so always follow a few tracks, and like you did now, ask questions.

a7

It does update but if your code inside the while loop allows it to.

Thank you for answering. Can you explain that for a beginner? I don't know what an interior is and how it works nor do I know about the AVR core thing. Thank you!!!!

interior?

If you don't know what interrupts are, you are unlikely to be using them directly.

There are untold number of tutorials on using interrupts in the Arduino ecosystem available on the web for the simple act of googling arduino interrupts.

Thank you ! - I had a typo - I will read up on it

Do you have code that doesn't work?
Post it here, following the guidelines, and it will be much easier to help you.

I figured it out. And I was hesitant to send my code here because it's way too long...10weeks of work!- thanks to all of you. I found the problem. I simply need to re-ask for reading of Millis in every while or for loop. I also asked for storing millis in only one function, which wasn't always called...

2 Likes

Glad you sorted it out.

1 Like