I'm programming a swimming stopwatch with arduino.
The problem I'm facing now is that the time is exported to the serial monitor in miliseconds. Is there a way to display it in minute.seconds.1/100seconds ? For example: 0.29.18 in stead of 29180.
This is a start, but is does not reserve a fixed number of digits when displayed (i.e., 125232 is displayed as 2.5.232. not 02.05.32). You need to figure that out.
void setup() {
Serial.begin(9600);
}
void loop() {
char input[10];
int charsRead;
unsigned long mil;
if (Serial.available()) {
charsRead = Serial.readBytesUntil('\n', input, sizeof(input) - 1); // collect number of millis
input[charsRead] = '\0'; // make a string
mil = strtoul(input, NULL, 10);
DisplayAsTime(mil);
}
}
void DisplayAsTime(unsigned long mil)
{
int minutes;
int seconds;
int hseconds;
Serial.print("Total milliseconds = ");
Serial.println(mil);
minutes = mil / 60000L; // extract minutes
mil -= minutes * 60000L;
seconds = mil / 1000L; // extract seconds
hseconds = mil - (seconds * 1000L);
Serial.print(minutes);
Serial.print(".");
Serial.print(seconds);
Serial.print(".");
Serial.println(hseconds);
}
Thank you! I think I can use that!
When you push the start button, the current millis() is stored into an int-value. There are three buttons (lane one, two and three), en when these buttons are pushed the difference between the int-value en the current millis() is stored in an int called finishtime1 / finishtime2 and finishtime3.
I think I can use your method to display finishtime as a human readable number. Thank you!