Skip to main content
5 of 6
deleted 146 characters in body
user avatar
user avatar

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification, paragraph 6.3.1.3, the upper 16 bits are discarded.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

user6971