I was looking at the blink without delay sketch and I was trying to modify it so the LED would start blinking after 1000 ms. I changed the previousMillis variable to 1000, but the program didn't change. In fact, it doesn't seem to change for any value of previousMillis. I thought that this would change the if statement:
if (currentMillis - previousMillis >= interval)
because 2000ms would have to pass for currentMillis - previousMillis to be equal to 1000ms (interval). What am I missing?
previousMillisto 1000 then, initially,currentMillis - previousMillisis −1000. But you are dealing with unsigned numbers, which cannot be negative, so the subtraction wraps around and you get 2^32−1000 = 4294966296. – Edgar Bonet Oct 01 '16 at 20:51unsignedfrom both variables and it works now. However, is there any downside to this? And any better solutions? – tootin' putin Oct 01 '16 at 21:15unsigned]?_” Yes.millis()will eventually overflow. Unsigned overflow is well behaved, whereas signed overflow is undefined behavior in C and C++. “_any better solutions?_” You can set an initialintervaland change it later. – Edgar Bonet Oct 02 '16 at 18:29