What does the % modulus symbol mean in dumbest terms? I don't understand.
Thank you.
It returns the remainder of the integer division of the left side by the right side.
e.g.
7 % 4 = 3
Have a look at: http://arduino.cc/en/Reference/Modulo
Okay cool,
Thanks
"%" can be used to display stuff like minutes and seconds from a total number of seconds. For example:
int totalSeconds = 250;
int minutes = totalSeconds / 60; //minutes = 4
int seconds = totalSeconds % 60; //seconds = 10
Serial.print(minutes);
Serial.print(":");
Serial.print(seconds);
Serial Output:
4:10
John_S:
"%" can be used to display stuff like minutes and seconds from a total number of seconds. For example:int totalSeconds = 250;
int minutes = totalSeconds / 60; //minutes = 4
int seconds = totalSeconds % 60; //seconds = 10
Serial.print(minutes);
Serial.print(":");
Serial.print(seconds);
What if it is 4:09? Will it display correctly? Serial Output: 4:10
What if it is 4:09? Will it display correctly?
No, it will show 4:9
Thanks for the heads up. To get the leading zero, you need an extra line of code:
Serial.print(minutes);
Serial.print(":");
if (seconds<10) Serial.print("0");
Serial.print(seconds);