Hi
I am new to the Arduino and I am trying to make some code to ato adjust for daylight savings.
Here is what I have written.
I am changing my time and date to 1:59am on the 25/9/2011 and trying to see if it changes forward from 2am to 3am and also setting it manually to 2:59am on the 1/4/2012 to see if it switches back again but with either scenario nothing happens so I guess I have got the code wrong.
The ds1307 seems to be reading and setting the time correctly. I have set up an lcd clock with it successfully and also just set and read to and from it via serial monitor so it is working correctly.
Could someone please tell me where I am going wrong.
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson
byte DOW,MTH,DATE,DST,HR;
void setup()
{
Serial.begin(9600);
byte dows,mnths,dts,DST,hrs;
RTC.stop();
RTC.set(DS1307_SEC,20); //set the seconds
RTC.set(DS1307_MIN,59); //set the minutes
RTC.set(DS1307_HR,2); //set the hours
RTC.set(DS1307_DOW,1); //set the day of the week
RTC.set(DS1307_DATE,1); //set the date
RTC.set(DS1307_MTH,4); //set the month
RTC.set(DS1307_YR,12); //set the year
RTC.start();
}
void loop()
{
// Daylight savings until 2020 for New Zealand
// Daylight savings changes forward from 2:00to 3:00on the last Sunday in September,
// and changes back from 3:00to 2:00 on the first Sunday of April
// so days between 25 and 31 in September and 1 to 6 in April is covered by this code
if (DOW == 1 && MTH == 4 || MTH == 9 && HR <1 && HR >4) // DST schedule for next ten years to october 2019 condition start in march or october
{
DST = digitalRead(1060); // read Previous DST status,
if (DOW == 1 && MTH == 4 && DATE <= 1 && DATE >=6 && HR == 2 && DST==0) // time forward from 02:00 to 03:00 in march if DSt status ==0 else don't change time!
{
RTC.set(DS1307_HR,3); //set the hours to 02:00 // when status was ZERO (0) then change time from 02:00 to 03:00 hr
digitalWrite(1060, 1); // daylight saving flag // Write DST statusflag to ONE(1) to prevent multiple changes in hours, only for once in March
}
if (DOW == 1 && MTH == 9 && DATE >= 25 && DATE <=31 && HR == 3 && DST==1) // time backwards from 3:00 to 02:00 in october if DSt status ==1 else don't change time!
{
RTC.set(DS1307_HR,2); //set the hours to 03:00
digitalWrite(1060, 0); // daylight saving flag // Write DST statusflag to ZERO to prevent multiple changes in hours, only for once in October
}
}
{
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
Serial.print(":");
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
Serial.print(":");
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
Serial.print(" "); // some space for a more happy life
Serial.print(RTC.get(DS1307_DATE,false));//read date
Serial.print("/");
Serial.print(RTC.get(DS1307_MTH,false));//read month
Serial.print("/");
Serial.print(RTC.get(DS1307_YR,false)); //read year
Serial.println();
delay(1000);
}
}
Thanks