char timebuf[10]; // Time
char datebuf[10]; // Date
int year2digit; // 2 digit year
int year4digit; // 4 digit year
void setup(void) {
}
void loop(void) {
tmElements_t tm;
if (RTC.read(tm)) {
year2digit = tm.Year - 30; // 2 digit year variable
// year4digit = tm.Year + 1970; // 4 digit year variable
Print;
}
delay(1000); // Delay of 1sec
}
void Print(){
Serial.sprintf(timebuf, "%02d:%02d:%02d",tm.Hour, tm.Minute, tm.Second ); // format time
Serial.sprintf(datebuf, "%02d/%02d/%02d",tm.Day, tm.Month, year2digit ); // format date
sprintf prints to a string buffer, so it isn't surprising that Serial doesn't implement it.
Serial does, however, implement a method to print the contents of a string buffer, called "print".
Please get into the habit of using code tags when posting code.
houssienmortada:
I HAVE THIS ISSUE AND I TRIED EVERYTHING PLEASE HELP
Try as hard as you may, sprintf will never work with HardwareSerial because H.S. has no function (member) with that name.
I think what you want to do is THIS:
int hours = 4;
int mins = 34;
char buffer [64]; // must be large enough for your whole string!
sprintf (buffer, "The time is HOURS: %02d, MINUTES: %02d", hours, mins).
Serial.print (buffer);