I have the following code:
#include <DS3231.h>
#include <Wire.h>
#include <stdio.h>
DS3231 Clock;
bool Century = false;
bool h12;
bool PM;
char currDate[24];
char currTime[22];
long lastRun = 0;
int pause = 1000;
void setup() {
Wire.begin();
Serial.begin(57600);
}
void loop() {
if (millis() - lastRun > pause) {
sprintf(currDate, "Current Date: 20%02d/%02d/%02d", Clock.getYear(), Clock.getMonth(Century), Clock.getDate());
sprintf(currTime, "Current Time: %02d:%02d:%02d", Clock.getHour(h12, PM), Clock.getMinute(), Clock.getSecond());
Serial.println(currDate);
Serial.println(currTime);
Serial.print('\n');
lastRun = millis();
}
}
And the output I'm getting is:
Current Date: 2013/01/13Current Time: 23:31:49
Current Time: 23:31:49
Current Date: 2013/01/13Current Time: 23:31:50
Current Time: 23:31:50
Current Date: 2013/01/13Current Time: 23:31:51
Current Time: 23:31:51
Can anyone explain to me why it appears that the 'currTime' variable gets tacked onto the end of the 'currDate' one? If I just output 'currDate', I get:Current Date: 2013/01/13Current Time: 23:32:27
Why's that?