I have found some code in the forum to convert from seconds to time. I make a function from it. But it will not compile.
Why can't I return hrMinSec? What to change? I want to get the string out of the function.
Does the sec %= 60 format the seconds with two characters?
char secondsToHMS(unsigned int seconds, const char ms){
unsigned int tme=0;
if(ms == 'j'){ // If value is millis (milliseconds)
tme = seconds / 1000;
} else {
tme = seconds;
}
int hr = tme/3600; //Number of seconds in an hour
int mins = (tme-hr*3600)/60; //Remove the number of hours and calculate the minutes.
int sec = tme-hr*3600-mins*60; //Remove the number of hours and minutes, leaving only seconds.
sec %= 60;
mins %= 60;
hr %= 24;
String hrMinSec = (String(hr) + ":" + String(mins) + ":" + String(sec)); //Converts to HH:MM:SS string. This can be returned to the calling function.
Serial.print("String Time: ");Serial.println (hrMinSec);
return hrMinSec;
}
If you would post the entire code, or reduced complete sketch illustrating the problem, and any error message, there would be less guessing and a faster time to solving this.
Without seeing more, just making the return type of secondsToHMD be String instead of char would get you going.