aboutsummaryrefslogtreecommitdiff
path: root/arduino_sketch/fuzzy_alarm_clock_ds1307
diff options
context:
space:
mode:
Diffstat (limited to 'arduino_sketch/fuzzy_alarm_clock_ds1307')
-rw-r--r--arduino_sketch/fuzzy_alarm_clock_ds1307/fuzzy_alarm_clock_ds1307.pde43
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