aboutsummaryrefslogtreecommitdiff
path: root/ds1307
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2011-09-02 10:42:22 +0200
committerElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2011-09-02 10:44:42 +0200
commit1643b2cfb8fe7dfc7b3c2d57190a540c87b4e87a (patch)
treef4b02c2ba4489506c27cccae1ad78cce3c532af4 /ds1307
parent16af2a7ec13e481c993d31bdfe6d9b2cc644f7a4 (diff)
Read backed up status from the DS1307 (partial)
Diffstat (limited to 'ds1307')
-rw-r--r--ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde42
1 files changed, 35 insertions, 7 deletions
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 () {