From 038e0ba8909426236503afe454f0e072f49a2232 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 2 Jan 2012 22:17:29 +0100 Subject: Added pushbutton to stop the SED --- .../fuzzy_alarm_clock_ds1307.pde | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 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 a4e0040..9b2e0c9 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 @@ -38,12 +38,16 @@ #define APIN0 3 #define APIN1 11 +#define IINT 0 +#define IPIN 2 + int st = 0; // alarm status (minutes from alarm - TIN) char alarms[NALARMS][5]; // alarm settings char cmin; // current minute int a = -1; // current alarm char dbg = 0; // print debug informations bool ringing = false; // sound the alarm +bool pressed = false; // stop button status #define NFREQ 9 int freq[] = { 255, 192, 128, 96, 64, 96, 128, 192, 255 }; // frequencies for the alarm @@ -61,6 +65,8 @@ void setup () { TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM20); TCCR2B = _BV(WGM22) | _BV(CS22); + attachInterrupt(IINT, button_pressed, HIGH); + digitalWrite(RPIN,HIGH); digitalWrite(YPIN,LOW); digitalWrite(BPIN,LOW); @@ -110,7 +116,11 @@ void loop () { Serial.print(", a: "); Serial.print(a,DEC); Serial.print(", cmin: "); - Serial.println(cmin,DEC); + Serial.print(cmin,DEC); + Serial.print(", ringing: "); + Serial.print(ringing); + Serial.print(", pressed: "); + Serial.println(pressed); } // act on status: LEDs and buzzer @@ -118,9 +128,15 @@ void loop () { set_leds(); } if ( st == TIN ) { - ringing = true; + if ( RTC.getSeconds() < 5 ) { + ringing = true; + } + if ( pressed ) { + ringing = false; + } } else { ringing = false; + pressed = false; } if ( ringing ) { ring_alarm(); @@ -301,6 +317,10 @@ void s_print_help() { Serial.println(" h - print this help"); } +void button_pressed() { + pressed = true; +} + // ****** Time management *************************************************** // // Set the current time -- cgit v1.2.3