From 1643b2cfb8fe7dfc7b3c2d57190a540c87b4e87a Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 2 Sep 2011 10:42:22 +0200 Subject: Read backed up status from the DS1307 (partial) --- ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde | 42 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'ds1307/arduino_sketch') diff --git a/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde b/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde index bf1c8f2..fd0682c 100644 --- a/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde +++ b/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde @@ -7,7 +7,7 @@ // "dawn" + "daylight" + blue blinding light #define TOUT 75 -// number of available alarms +// number of available alarms; max 10 for storage in the DS1307 ram #define NALARMS 4 // pins and addressed @@ -25,7 +25,6 @@ void setup () { Serial.begin(9600); Wire.begin(); - set_time(11,9,2,5,0,0,0); pinMode(RPIN,OUTPUT); pinMode(YPIN,OUTPUT); @@ -35,12 +34,41 @@ void setup () { digitalWrite(YPIN,0); digitalWrite(BPIN,0); - // read alarms and status from storage - for ( int i = 0 ; i < NALARMS ; i ++ ) { - alarms[i][0] = 0; + // if the RTC is already running read alarms and status + Wire.beginTransmission(DS1307_ADDRESS); + Wire.send(0); + Wire.endTransmission(); + + Wire.requestFrom(DS1307_ADDRESS, 1); + char running = Wire.receive(); + running = !(running>>7); + + if ( running ) { + Wire.requestFrom(DS1307_ADDRESS, 12 + NALARMS * 5); + for (int i = 0; i < 8 ; i ++ ) { + Wire.receive(); + } + st = Wire.receive(); + a = Wire.receive(); + cmin = Wire.receive(); + for ( int i = 0; i < NALARMS ; i ++ ) { + for ( int j = 0; j < 5 ; j ++ ) { + alarms[i][j] = Wire.receive(); + } + } + } else { + for ( int i = 0 ; i < NALARMS ; i ++ ) { + for ( int j = 0; j < 5 ; j ++ ) { + alarms[i][j] = 0; + } + } + st = 0; + a = -1; + // DEBUG: we don't want to set the time until we receive + // it from serial, but serial is not implemented yet + set_time(11,9,2,5,0,0,0); } - st = 0; - a = -1; + } void loop () { -- cgit v1.2.3