majenko:
b is an int - therefore it cannot store more than 32767. As it's the only variable in the calculation at that point, the result is also an int.
Change it to an unsigned long.
Don't have to change the variable 'b' to get the right result. The "B*60" happens first so changing 60 to 60L or 60UL will cause all the math to be done with 'long' or 'unsigned long' values.
600,000 in hex is 0x927C0. A 16-bit integer can only store the last 4 digits: 0x27C0 which in decimal is 10,176. Using long (32-bit) integers allows for all 5 digits to be kept.
majenko:
b is an int - therefore it cannot store more than 32767. As it's the only variable in the calculation at that point, the result is also an int.
Change it to an unsigned long.
Don't have to change the variable 'b' to get the right result. The "B*60" happens first so changing 60 to 60L or 60UL will cause all the math to be done with 'long' or 'unsigned long' values.
600,000 in hex is 0x927C0. A 16-bit integer can only store the last 4 digits: 0x27C0 which in decimal is 10,176. Using long (32-bit) integers allows for all 5 digits to be kept.
johnwasser:
majenko:
b is an int - therefore it cannot store more than 32767. As it's the only variable in the calculation at that point, the result is also an int.
Change it to an unsigned long.
Don't have to change the variable 'b' to get the right result. The "B*60" happens first so changing 60 to 60L or 60UL will cause all the math to be done with 'long' or 'unsigned long' values.
600,000 in hex is 0x927C0. A 16-bit integer can only store the last 4 digits: 0x27C0 which in decimal is 10,176. Using long (32-bit) integers allows for all 5 digits to be kept.
millis() returns an unsigned long. You should try and keep all your data types in a comparison the same so as to avoid any problems. unsigned takes no more space than signed, so it's a no-brainer.