What does this bit of code do?

Hello,

Im using Jchristensen's code (SetSerial) to set the time using the serial monitor.
Ive been looking at the code trying to understand it but I don't know what this bit of code does.
Does anyone know?

void printI00(int val, char delim)
{
    if (val < 10) Serial << '0';
    Serial << _DEC(val);
    if (delim > 0) Serial << delim;
    return;
}

Full code:

Thank you

Note this in the sketch

#include <Streaming.h>

which enables the use of << to send data to Serial

It's a bit of a hack for provide a nicely-formatted time on the serial output.

If the time was, say, five minutes past ten, you might have:

byte hour = 10;
byte minute = 5;
Serial.print(hour);
Serial.print(":");
Serial.println(minute);

...and the result would be "10:5", which probably wouldn't be what you wanted. The code you posted detects if the value is less than 10, and pads it with a zero, so you'd get: "10:05" instead.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.