Having downloaded a sketch to display Time, Date and Temp etc. The Day of the Week data displayed shows a day which is two ahead of actual. I have exchanged the DS1307 module but same issue. I used a completely different and simple code to access date etc and that works fine so conclusion is that original downloaded code is in error. I cannot fathom out where that could be and if I Serial print various points in the sketch, I only see a "post error" condition. Some of the relevant code follows and I would appreciate any pointers as I'm just getting to grips with the Arduino so far. Thanks.
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const char str[][10] PROGMEM =
{
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
*psz = '\0';
code--;
if (code < 7)
{
strncpy_P(psz, str[code], len);
psz[len] = '\0';
}
return(psz);
}
void getTime(char *psz, bool f = true)
// Code for reading clock time
{
sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
}
void getsecond(char *psz)
// Code for reading clock date
{
char szBuf[10];
sprintf(psz, "%02d", RTC.s);
}
void getDate(char *psz)
// Code for reading clock date
{
char szBuf[10];
sprintf(psz, "%d %s %04d", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1), RTC.yyyy);
//Serial.println (sprintf(psz, "%d %s %04d", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1), RTC.yyyy));
}
void getTemperature()
{
DHT.read11(DHT11_PIN);
h = DHT.humidity;
t = DHT.temperature;
// Read temperature as Fahrenheit
f = (1.8 * DHT.temperature)+32;
}
void setup(void)
{
// initialise the LED display
Serial.begin (9600);
P.begin(4);
// Set up zones for 4 halves of the display
// Each zone gets a different font, making up the top
// and bottom half of each letter
P.setZone(0, 0, 1);
P.setZone(1, 2, 7);
P.setZone(2, 10, 15);
P.setZone(3, 8, 9);
P.setFont(0, NULL);
P.setFont(1, BigFontLower);
P.setFont(2, BigFontUpper);
P.setFont(3, NULL);
P.displayZoneText(0, szsecond, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(1, szTime, PA_LEFT, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, szTime, PA_LEFT, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, szMesg, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.addChar('$', degC);
P.addChar('&', degF);
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
RTC.readTime();
}
void loop(void)
{
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(3))
{
switch (display)
{
case 0: // day of week
P.setTextEffect(3, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
dow2str(RTC.dow, szMesg, MAX_MESG);
break;
case 1: // Calendar
P.setTextEffect(3, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
getDate(szMesg);
break;