piccy:
if i understand what you are saying , you say to test for the date being inside the start and end dates of BST and simply add or subtract 1 hour from the displayed value , is that correct ?
Yes, something like that.
But as long as you just want to read the local time from RTC, you never have to subtract anything. Either you add nothing or you add one hour.
I've written a replacement for your function "getDateDs1307(...)":
Summertime change hour is the same in UK and all over Europe:
boolean summertime_EU(int year, byte month, byte day, byte hour, byte tzHours)
// European Daylight Savings Time calculation by "jurs" for German Arduino Forum
// input parameters: "normal time" for year, month, day, hour and tzHours (0=UTC, 1=MEZ)
// return value: returns true during Daylight Saving Time, false otherwise
// valid year range is from year 2000 ... 2099
{
if (month<3 || month>10) return false; // keine Sommerzeit in Jan, Feb, Nov, Dez
if (month>3 && month<10) return true; // Sommerzeit in Apr, Mai, Jun, Jul, Aug, Sep
if (month==3 && (hour + 24 * day)>=(1 + tzHours + 24*(31 - (5 * year /4 + 4) % 7)) || month==10 && (hour + 24 * day)<(1 + tzHours + 24*(31 - (5 * year /4 + 1) % 7)))
return true;
else
return false;
}
void getDateDs1307(byte &second,byte &minute, byte &hour,byte &dayOfWeek,byte &dayOfMonth,byte &month,byte &year)
{
// read date/time from RTC running in UTC time
// and adjust summertime if necessary
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
second = bcdToDec(Wire.read() & 0x7f);
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0x3f);
dayOfWeek = bcdToDec(Wire.read());
dayOfMonth = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
// do summertime test for timezone UTC+0 (i.e. UK)
if (summertime_EU(year+2000, month, dayOfMonth, hour, 0)==false) return; // no summertime, leave function
hour++; // adjust summertime by adding one hour
if (hour<24) return; // same day, leave function
hour=0; // day has changed because of summertime adjustment
dayOfWeek= (dayOfWeek+1)%7;
dayOfMonth++;
byte daysInMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
if (dayOfMonth<=daysInMonth[month-1]) return; // same month, leave function
dayOfMonth=1; // month has changed because of summertime adjustment
month++;
}
Please notice that I also changed the "call by reference" parameters syntax from C-pointer-style to C++-reference-style, so that you also have to change the function call. Within your loop function remove this:
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// clock fwd check
if (DST ==0 && month ==3 && dayOfWeek ==1 && dayOfMonth >24 && hour >0){
bst_start();
}
// clock back check
if (DST ==1 && month ==10 && dayOfWeek ==7 && dayOfMonth >23 && hour >1){
bst_end();
}
and replace with that:
getDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
and remove bst_start()/bst_end() functions from your code.
The programming logic is then:
RTC must always be set to UTC-time (British winter time).
And when reading the time from RTC, it automatically gets adjusted to local summer time if needed.
Please test, that code is not really tested by me, I copied it together and adapted from functions that I use.