Print time with two '00's

Hi all.

So I am using the following code to get the time input from Blynk…

BLYNK_WRITE(V8)
{
  TimeInputParam t(param);
  if (t.hasStartTime())
  {
    doser4timeH=t.getStartHour();
    doser4timeM=t.getStartMinute();
  }
}

However when I enter a time with 00, ie 1200, and try to print this time to the LCD Widget, I only get 120. Is there any way to get the double 0 after? Is there a different data type to label ‘doser4timeM’ as?

Thanks all.
Steve

You should use the sprintf command to format your time.

Pete.

I did see that from my previous project used that, didn’t know if there was a different way. Ill try and adapt it thank you Pete. :slight_smile:

OK, so looking at my previous project that used this… this should work… but its now :thinking:

void savechanges()
{
  if (printscreen == 1)  // ALKALINITY
  {
    lcd.clear();
    lcd.print(0, 0, "Alkalinity: ");
    
    sprintf(bufTime, "%02d:%02d", doser1timeH, doser1timeM);
    
  lcd.print(0, 1, "T:");lcd.print(2, 1, bufTime);lcd.print(8, 1, " D:");lcd.print(11, 1, doser1amount);lcd.print(13, 1, "ml");

Any ideas as to why?

Is this function being called and the if statement evaluated as true?
Do the other pieces of text display correctly?
What exactly do you see on your LCD?
Have you tried adding-in serial print statements to debug what’s happening?

Pete.

Hi Pete. Yes its all displaying properly, other than I am getting one 0 instead of two 00 at say 1100 or 1200 because the doser1timeM is only saving 0 from the blink clock.

Yes the print screen if statement is reading true and printing to the LCD, but just as above. I did have the serial prints but removed them as its working fine, other than only getting a single 0 instead of the two. Even in the serial print I am only getting one 0.

Don’t worry, I’ve figured it. :slight_smile:
I put an if statement in.

if (doser3timeM == 0)
    {
      lcd.print(6, 1, "0");
    } 

The above just adds the second 0 in. :slight_smile: