You're not absorbing the material in the references. Your code doesn't follow the prescribed design patterns. How can we help? Is there some reason you decided to go off and do it in a totally non-standard way?
I'm talking about millis(); rollover overflowing and going back to zero after 49.7 days.
Don't you expect the 10 seconds to lapse well before 49.7 days?
When you subtract PreviousTime from CurrentTime you always get a positive answer. Even if CurrentTime is near zero because of a roll-over and PreviouTime is very large because it was just before the roll-over. The subtraction makes PreviousTime act as a small negative number which is subtracted from the small positive number to produce a larger positive number. YOU DON'T HAVE TO DO ANYTHING SPECIAL FOR MEASURING INTERVALS LESS THAN 49.7 DAYS.
The more correct terms are rolls over or overflows. An unsigned long variable (millis()) rolls over from 4,294,967,295 to 0. It starts over at 0 and counts up.
A long (signed long) data type rolls over at 2,147,483,647 to start again at -2,147,483,648 and counts up.
Thank you everyone, it seems that I need to go back and understand the core of the function. I posted my problem here too soon. I appreciate you taking the time to reply!
Well, I'm not sure about that. Most people post here before they solve a problem, not after! I think what you might have done too soon, is coding. However, it's not the core that you need to understand, it's the appropriate usage. 'millis()' itself is a really simple, obvious function. It's the design patterns that use it as an interval timer, etc., that have some subtlety and need some attention to learn. But those are not a mystery, most resources that talk about it, do exemplify the correct approach.
You might also like to clarify what happens in the 10 seconds. Seems to me that everything's supposed to stop, which is not the normal behaviour during a millis()-based "non-delaying-delay". Usually, the rest of the code needs to carry on while you wait for something to happen.
Maybe in this case you would use a while() which would end after the 10s is up, and check for the button inside the while and break if it's pressed.
you shouldn't re-edit postings so strong that given answers make no more sense. correctng typos or deleting empty lines is appreciated. Correcting more should be done in a new posting. in general posting complete sketches is a good idea. So please post your complete sketch.
if variables of type unsigned long are used for millis(). the pre-programmed math how substracting a (rolled over) small value from a big value
123 - 2.123.567.789 is done in a way that even in this case the if-condition
if (currentMillis - previousMillis >= myInterval) will work in all cases.
regardless of currentMillis or previousMillis beeing a small or big number
that's the reason why in all tutorials it is used this way