From 0dc9cd95010ac7ae60141629367d60472084f132 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Thu, 26 Jan 2012 07:04:08 +0100 Subject: arduino sketch: fix loading of status after lack of power --- .../fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'arduino_sketch') diff --git a/arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde b/arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde index 090f14e..1b5fd89 100644 --- a/arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde +++ b/arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde @@ -44,7 +44,7 @@ int st = 0; // alarm status (minutes from alarm - TIN) char alarms[NALARMS][5]; // alarm settings char cmin; // current minute -int a = -1; // current alarm +signed char a = -1; // current alarm char dbg = 0; // print debug informations bool ringing = false; // sound the alarm bool pressed = false; // stop button status @@ -88,10 +88,12 @@ void setup () { cmin = RTC.readData(0x0a); // This only works if the arduino had no power for a // "short" time. This is by design. :D - RTC.readClock(); - st = st + (RTC.getMinutes() - cmin) % 60; - cmin = RTC.getMinutes(); - save_status(); + if ( a >= 0 ) { + RTC.readClock(); + st = st + (RTC.getMinutes() - cmin) % 60; + cmin = RTC.getMinutes(); + save_status(); + } for ( int i = 0; i < NALARMS ; i ++ ) { for ( int j = 0; j < 5 ; j ++ ) { alarms[i][j] = RTC.readData(0x0b + i*5 + j); -- cgit v1.2.3