diff options
| author | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2011-09-02 23:05:49 +0200 | 
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2011-09-02 23:05:49 +0200 | 
| commit | 6c0e2a0c7e4f79087eccaca34bdefe86b6a9c423 (patch) | |
| tree | 48c261118e31659f35159b5e02a48169ed0d4bab /ds1307/arduino_sketch | |
| parent | 95e2e76f826079870d401609723283111a877658 (diff) | |
Save status in the ds1307 RAM
Diffstat (limited to 'ds1307/arduino_sketch')
| -rw-r--r-- | ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde | 27 | 
1 files changed, 18 insertions, 9 deletions
| diff --git a/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde b/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde index 224706a..54c6993 100644 --- a/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde +++ b/ds1307/arduino_sketch/fuzzy_alarm_clock_ds1307.pde @@ -35,15 +35,9 @@ void setup () {      digitalWrite(YPIN,255);      digitalWrite(BPIN,0); -    // DEBUG: we want to read the setup messages -     -    delay(5000); -    digitalWrite(YPIN,0); -      // if the RTC is already running read alarms and status,  -    // otherwise set everything to the default +    // otherwise set everything to a sane default      if ( RTC.readData(0x00) >> 7 ) { -        Serial.println("Setup the clock");          for ( int i = 0 ; i < NALARMS ; i ++ ) {              for ( int j = 0; j < 5 ; j ++ ) {                  alarms[i][j] = 0; @@ -51,12 +45,17 @@ void setup () {          }          st = 0;          a = -1; +        save_status();      } else {          st = RTC.readData(0x08);          a = RTC.readData(0x09);          cmin = RTC.readData(0x0a); -        // FIXME: we want to update st to the time passed  -        // since the data was saved +        // 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();          for ( int i = 0; i < NALARMS ; i ++ ) {              for ( int j = 0; j < 5 ; j ++ ) {                  alarms[i][j] = RTC.readData(0x0b + i*5 + j); @@ -95,6 +94,12 @@ void loop () {  } +void save_status() { +    RTC.writeData(0x08,st); +    RTC.writeData(0x09,a); +    RTC.writeData(0x0a,cmin); +} +  // ****** Serial interface management *************************************** //  void check_serial() { @@ -135,6 +140,7 @@ void s_set_alarm() {  }  void s_set_time() { +    RTC.start();      RTC.setYear(s_read_2dig());      RTC.setMonth(s_read_2dig());      RTC.setDate(s_read_2dig()); @@ -271,6 +277,7 @@ void check_time() {                      a = i;                      st = 1;                      cmin = mm; +                    save_status();                      if ( ( alarms[i][0] & 128 ) == 0 ) {                          // this alarm won't be repeated                          alarms[i] = { 0,0,0,0,0 }; @@ -286,6 +293,7 @@ void check_time() {          if ( cmin != mm ) {              cmin = mm;              st++; +            save_status();          }       } @@ -311,6 +319,7 @@ void set_leds() {        // reset stuff        st = 0;        a = -1; +      save_status();        analogWrite(RPIN,255);        analogWrite(YPIN,0);        analogWrite(BPIN,0); | 
