The problem set by my worksheet asks us to devise a program using Arduino Uno with limited function use i.e. no if statements and such only ints and parseints. This is my code so far:
int totalHrs;
int totalMinutes;
int totalSeconds;
int swimHours;
int swimMinutes;
int swimSeconds;
int bikeHours;
int bikeMinutes;
int bikeSeconds;
int runHours;
int runMinutes;
int runSeconds;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Please enter the number of hours for the swim");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
swimHours = Serial.parseInt();
Serial.println("Please enter the number of minutes for the swim");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
swimMinutes = Serial.parseInt();
Serial.println("Please enter the number of seconds for the swim");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
swimSeconds = Serial.parseInt();
Serial.println("Please enter the number of hours for the bike");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
bikeHours = Serial.parseInt();
Serial.println("Please enter the number of minutes for the bike");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
bikeMinutes = Serial.parseInt();
Serial.println("Please enter the number of seconds for the bike");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
bikeSeconds = Serial.parseInt();
Serial.println("Please enter the number of hours for the running");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
runHours = Serial.parseInt();
Serial.println("Please enter the number of minutes for the running");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
runMinutes = Serial.parseInt();
Serial.println("Please enter the number of seconds for the running");
while (!Serial.available()) {
//wait for the user to enter a value
;
}
runSeconds = Serial.parseInt();
totalHrs = swimHours + bikeHours + runHours;
Serial.print(totalHrs);
Serial.print("hr");
totalMinutes = swimMinutes + bikeMinutes + runMinutes;
Serial.print(totalMinutes % 60);
Serial.print("min");
totalSeconds = swimSeconds + bikeSeconds + runSeconds;
Serial.print(totalSeconds);
Serial.print("sec");
}
void loop() {
// put your main code here, to run repeatedly:
}
At the moment the calculations work as intended, but now I want it to convert and carry over to the next column for example 0hr90min0sec -> 1hr30min0sec.