diff options
| author | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-04-04 08:01:13 +0200 | 
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <elena.valhalla@gmail.com> | 2012-04-04 08:01:13 +0200 | 
| commit | ea4b646cb607083a133ba23d0f2153f6b070a58d (patch) | |
| tree | 445cea8b16380e0559d0cde7cccd1e9ccc040f1c /arduino_sketch/fuzzy_alarm_clock_ds1307 | |
| parent | d5eee780b798212131fe783cee76270081c0ef87 (diff) | |
arduino sketch: yellow+blue light if there is no alarm / running RTC.
If the clock has somehow lost its settings it is useful to know :)
Diffstat (limited to 'arduino_sketch/fuzzy_alarm_clock_ds1307')
| -rw-r--r-- | arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde | 43 | 
1 files changed, 35 insertions, 8 deletions
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 8d4c5ef..12ff745 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 @@ -100,7 +100,7 @@ void setup () {              }          }      } -     +    reset_leds();  }  void loop () { @@ -155,6 +155,21 @@ void save_status() {      RTC.writeData(0x0a,cmin);  } +int has_alarm() { +    if ( RTC.readData(0x00) >> 7 ) { +        return false; +    } +    for ( int i = 0; i < NALARMS ; i ++ ) { +        // we can skip checking the hour/minute field +        for ( int j = 0; j < 3 ; j ++ ) { +            if ( alarms[i][j] != 0 ) { +                return true; +            } +        } +    } +    return false; +} +  // ****** Serial interface management *************************************** //  void check_serial() { @@ -198,6 +213,7 @@ void s_set_alarm() {      Serial.print("Alarm ");      Serial.print(i,DEC);      Serial.println(" set."); +    reset_leds();  }  void s_set_time() { @@ -212,6 +228,7 @@ void s_set_time() {      RTC.setClock();      Serial.print("Time set: ");      s_print_time(); +    reset_leds();  }  int s_read_dig() { @@ -313,9 +330,7 @@ void s_reset_alarms() {      st = 0;      a = -1;      save_status(); -    analogWrite(RPIN,128); -    digitalWrite(YPIN,LOW); -    digitalWrite(BPIN,LOW); +    reset_leds();  }  void s_print_help() { @@ -419,10 +434,22 @@ void set_leds() {        st = 0;        a = -1;        save_status(); -      analogWrite(RPIN,128); -      analogWrite(YPIN,0); -      analogWrite(BPIN,0); -  } +      reset_leds(); +  }  +} + +void reset_leds() { +    if ( a < 0 ) { +        if ( has_alarm() ) { +            analogWrite(RPIN,128); +            analogWrite(YPIN,0); +            analogWrite(BPIN,0); +        } else { +            analogWrite(RPIN,0); +            analogWrite(YPIN,16); +            analogWrite(BPIN,16); +        } +    }  }  // PC speaker  | 
