Commits

Wagner Sartori Junior  committed 21c093a

Trocada música do alarme para MarioBros.

  • Participants
  • Parent commits 8bc9fb0

Comments (0)

Files changed (7)

File HT1632C/HT1632C.cpp

 
 void HT1632C::setup()
 {
-	pinMode(HT1632_CS, OUTPUT);
-	digitalWrite(HT1632_CS, HIGH);
-	pinMode(HT1632_WRCLK, OUTPUT);
-	pinMode(HT1632_DATA, OUTPUT);
-	pinMode(HT1632_CLK, OUTPUT);
+	pinModeFast2(HT1632_CS, OUTPUT);
+	digitalWriteFast2(HT1632_CS, HIGH);
+	pinModeFast2(HT1632_WRCLK, OUTPUT);
+	pinModeFast2(HT1632_DATA, OUTPUT);
+	pinModeFast2(HT1632_CLK, OUTPUT);
 	for (int i=1; i<=CHIP_MAX; i++) {
 		HT1632C::sendCmd(i, HT1632_CMD_SYSDIS); // Disable system
 		HT1632C::sendCmd(i, HT1632_CMD_COMS00); // 16*32, PMOS drivers
 
 void HT1632C::outputClkPulse()	//Output a clock pulse
 {
-	digitalWrite(HT1632_CLK, HIGH);
-	digitalWrite(HT1632_CLK, LOW);
+	digitalWriteFast2(HT1632_CLK, HIGH);
+	digitalWriteFast2(HT1632_CLK, LOW);
 }
 
 void HT1632C::chipSelect(int select)
 {
 	unsigned char tmp = 0;
 	if (select < 0) { // Enable all HT1632C
-		digitalWrite(HT1632_CS, LOW);
+		digitalWriteFast2(HT1632_CS, LOW);
 		for (tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
 	} else if(select==0) { //Disable all HT1632Cs
-		digitalWrite(HT1632_CS, HIGH);
+		digitalWriteFast2(HT1632_CS, HIGH);
 		for(tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
 	} else {
-		digitalWrite(HT1632_CS, HIGH);
+		digitalWriteFast2(HT1632_CS, HIGH);
 		for(tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
-		digitalWrite(HT1632_CS, LOW);
+		digitalWriteFast2(HT1632_CS, LOW);
 		HT1632C::outputClkPulse();
-		digitalWrite(HT1632_CS, HIGH);
+		digitalWriteFast2(HT1632_CS, HIGH);
 		tmp = 1;
 		for( ; tmp<select; tmp++) {
 			HT1632C::outputClkPulse();
 void HT1632C::writeBits(byte bits, byte firstbit)
 {
 	while (firstbit) {
-		digitalWrite(HT1632_WRCLK, LOW);
+		digitalWriteFast2(HT1632_WRCLK, LOW);
 		if (bits & firstbit) {
-			digitalWrite(HT1632_DATA, HIGH);
+			digitalWriteFast2(HT1632_DATA, HIGH);
 		} else {
-			digitalWrite(HT1632_DATA, LOW);
+			digitalWriteFast2(HT1632_DATA, LOW);
 		}
-		digitalWrite(HT1632_WRCLK, HIGH);
+		digitalWriteFast2(HT1632_WRCLK, HIGH);
 		firstbit >>= 1;
 	}
 }
 // Sound.h
-
-
 #include <WProgram.h>
 #include "Sound.h"
 
-
-#define _USE_ARDUINO_TONE
-
-
-#define SPEAKER_PIN1	6	// PC6;
-#define SPEAKER_PIN2	7	// PC7;
-
+#define SPEAKER_PIN	6
 
 #ifndef _USE_ARDUINO_TONE
 	// instance of the tone library (by B.Hagman);
-	Tone noiseMaker;	// used for beeps and alarm;
+	Tone tone1;	// used for beeps and alarm;
 #endif
 
 
-
-
 //*********************************************************************************************************
 void setupSpeaker()
 {
 	// REM: should exploit the 2 sound levels, by driving both speaker pins;
-	pinMode(SPEAKER_PIN1, OUTPUT);
-	digitalWrite(SPEAKER_PIN1, LOW);
+//	pinMode(SPEAKER_PIN1, OUTPUT);
+//	digitalWrite(SPEAKER_PIN1, LOW);
 
-	pinMode(SPEAKER_PIN2, OUTPUT);
+//	pinMode(SPEAKER_PIN2, OUTPUT);
 
 #ifndef _USE_ARDUINO_TONE
-	noiseMaker.begin(SPEAKER_PIN2);
+	tone1.begin(6);
 #endif
 }
 
 #endif
 
 	// alarm can be stopped from remote control or by pressing any of the buttons;
+
+
+#ifdef _USE_ARDUINO_TONE
 	for (int thisNote = 0; thisNote < 5; thisNote ++)
 	{
-
-	#ifdef _DEBUG_
-		Serial.print("Note #");
-		Serial.println(thisNote);
-	#endif
-
-
-	#ifdef _USE_ARDUINO_TONE
 		tone(SPEAKER_PIN2, notes[thisNote], durations[thisNote]);
 		delay(durations[thisNote]);
-	#else
-		noiseMaker.play(notes[thisNote]);
-		delay(durations[thisNote]);
-		noiseMaker.stop();
-	#endif
 	}
+#else
+	tone1.play(660,100);
+	delay(75);tone1.play(660,100);
+	delay(150);tone1.play(660,100);
+	delay(150);tone1.play(510,100);
+	delay(50);tone1.play(660,100);
+	delay(150);tone1.play(770,100);
+	delay(275);tone1.play(380,100);
+	delay(287);tone1.play(510,100);
+	delay(225);tone1.play(380,100);
+	delay(200);tone1.play(320,100);
+	delay(250);tone1.play(440,100);
+	delay(150);tone1.play(480,80);
+	delay(165);tone1.play(450,100);
+	delay(75);tone1.play(430,100);
+	delay(150);tone1.play(380,100);
+	delay(100);tone1.play(660,80);
+	delay(100);tone1.play(760,50);
+	delay(75);tone1.play(860,100);
+	delay(150);tone1.play(700,80);
+	delay(75);tone1.play(760,50);
+	delay(175);tone1.play(660,80);
+	delay(150);tone1.play(520,80);
+	delay(75);tone1.play(580,80);
+	delay(75);tone1.play(480,80);
+	delay(175);tone1.play(510,100);
+	delay(275);tone1.play(380,100);
+	delay(200);tone1.play(320,100);
+	delay(250);tone1.play(440,100);
+	delay(150);tone1.play(480,80);
+	delay(165);tone1.play(450,100);
+	delay(75);tone1.play(430,100);
+	delay(150);tone1.play(380,100);
+	delay(100);tone1.play(660,80);
+	delay(100);tone1.play(760,50);
+	delay(75);tone1.play(860,100);
+	delay(150);tone1.play(700,80);
+	delay(75);tone1.play(760,50);
+	delay(175);tone1.play(660,80);
+	delay(150);tone1.play(520,80);
+	delay(75);tone1.play(580,80);
+	delay(75);tone1.play(480,80);
+	delay(250);tone1.play(500,100);
+	delay(150);tone1.play(760,100);
+	delay(50);tone1.play(720,100);
+	delay(75);tone1.play(680,100);
+	delay(75);tone1.play(620,150);
+	delay(150);tone1.play(650,150);
+	delay(150);tone1.play(380,100);
+	delay(75);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(150);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(50);tone1.play(570,100);
+	delay(110);tone1.play(500,100);
+	delay(150);tone1.play(760,100);
+	delay(50);tone1.play(720,100);
+	delay(75);tone1.play(680,100);
+	delay(75);tone1.play(620,150);
+	delay(150);tone1.play(650,200);
+	delay(150);tone1.play(1020,80);
+	delay(150);tone1.play(1020,80);
+	delay(75);tone1.play(1020,80);
+	delay(150);tone1.play(380,100);
+	delay(150);tone1.play(500,100);
+	delay(150);tone1.play(760,100);
+	delay(50);tone1.play(720,100);
+	delay(75);tone1.play(680,100);
+	delay(75);tone1.play(620,150);
+	delay(150);tone1.play(650,150);
+	delay(150);tone1.play(380,100);
+	delay(75);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(150);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(50);tone1.play(570,100);
+	delay(110);tone1.play(500,100);
+	delay(150);tone1.play(760,100);
+	delay(50);tone1.play(720,100);
+	delay(75);tone1.play(680,100);
+	delay(75);tone1.play(620,150);
+	delay(150);tone1.play(650,200);
+	delay(150);tone1.play(1020,80);
+	delay(150);tone1.play(1020,80);
+	delay(75);tone1.play(1020,80);
+	delay(150);tone1.play(380,100);
+	delay(150);tone1.play(500,100);
+	delay(150);tone1.play(760,100);
+	delay(50);tone1.play(720,100);
+	delay(75);tone1.play(680,100);
+	delay(75);tone1.play(620,150);
+	delay(150);tone1.play(650,150);
+	delay(150);tone1.play(380,100);
+	delay(75);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(150);tone1.play(430,100);
+	delay(75);tone1.play(500,100);
+	delay(50);tone1.play(570,100);
+	delay(210);tone1.play(585,100);
+	delay(275);tone1.play(550,100);
+	delay(210);tone1.play(500,100);
+	delay(180);tone1.play(380,100);
+	delay(150);tone1.play(500,100);
+	delay(150);tone1.play(500,100);
+	delay(75);tone1.play(500,100);
+	delay(150);tone1.play(500,60);
+	delay(75);tone1.play(500,80);
+	delay(150);tone1.play(500,60);
+	delay(175);tone1.play(500,80);
+	delay(75);tone1.play(580,80);
+	delay(175);tone1.play(660,80);
+	delay(75);tone1.play(500,80);
+	delay(150);tone1.play(430,80);
+	delay(75);tone1.play(380,80);
+	delay(300);tone1.play(500,60);
+	delay(75);tone1.play(500,80);
+	delay(150);tone1.play(500,60);
+	delay(175);tone1.play(500,80);
+	delay(75);tone1.play(580,80);
+	delay(75);tone1.play(660,80);
+	delay(225);tone1.play(870,80);
+	delay(162);tone1.play(760,80);
+	delay(300);tone1.play(500,60);
+	delay(75);tone1.play(500,80);
+	delay(150);tone1.play(500,60);
+	delay(175);tone1.play(500,80);
+	delay(75);tone1.play(580,80);
+	delay(175);tone1.play(660,80);
+	delay(75);tone1.play(500,80);
+	delay(150);tone1.play(430,80);
+	delay(75);tone1.play(380,80);
+	delay(300);tone1.play(660,100);
+	delay(75);tone1.play(660,100);
+	delay(150);tone1.play(660,100);
+	delay(150);tone1.play(510,100);
+	delay(50);tone1.play(660,100);
+	delay(150);tone1.play(770,100);
+	delay(225);tone1.play(380,100);
+#endif
 }
 
 
 	tone(SPEAKER_PIN2, NOTE_C8, 200);
 #else
 	// beep after reset;
-	noiseMaker.play(NOTE_C8, 200);
+	tone1.play(NOTE_C8,200);
 #endif
 }
-
-
-
-
 
 
 //*	Apr  1,	2010	<MLS> modified to use the non-C++ version of tone
-#define	_USE_ARDUINO_TONE
+//#define	_USE_ARDUINO_TONE
 #ifdef _USE_ARDUINO_TONE
 	//*	tone is included in WProgram.h
 	#include "ToneNotes.h"
 
 #else
-	#include "WiseTone.h"
+	#include "Tone/Tone.h"
 #endif
 
 

File Tone/Tone.cpp

+/* $Id: Tone.cpp 119 2010-07-17 18:56:36Z bhagman@roguerobotics.com $
+
+  A Tone Generator Library
+
+  Written by Brett Hagman
+  http://www.roguerobotics.com/
+  bhagman@roguerobotics.com
+
+    This library is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+*************************************************/
+
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include <wiring.h>
+#include <pins_arduino.h>
+#include "Tone.h"
+
+#if defined(__AVR_ATmega8__)
+#define TCCR2A TCCR2
+#define TCCR2B TCCR2
+#define COM2A1 COM21
+#define COM2A0 COM20
+#define OCR2A OCR2
+#define TIMSK2 TIMSK
+#define OCIE2A OCIE2
+#define TIMER2_COMPA_vect TIMER2_COMP_vect
+#define TIMSK1 TIMSK
+#endif
+
+// timerx_toggle_count:
+//  > 0 - duration specified
+//  = 0 - stopped
+//  < 0 - infinitely (until stop() method called, or new play() called)
+
+#if !defined(__AVR_ATmega8__)
+volatile int32_t timer0_toggle_count;
+volatile uint8_t *timer0_pin_port;
+volatile uint8_t timer0_pin_mask;
+#endif
+
+volatile int32_t timer1_toggle_count;
+volatile uint8_t *timer1_pin_port;
+volatile uint8_t timer1_pin_mask;
+volatile int32_t timer2_toggle_count;
+volatile uint8_t *timer2_pin_port;
+volatile uint8_t timer2_pin_mask;
+
+#if defined(__AVR_ATmega1280__)
+volatile int32_t timer3_toggle_count;
+volatile uint8_t *timer3_pin_port;
+volatile uint8_t timer3_pin_mask;
+volatile int32_t timer4_toggle_count;
+volatile uint8_t *timer4_pin_port;
+volatile uint8_t timer4_pin_mask;
+volatile int32_t timer5_toggle_count;
+volatile uint8_t *timer5_pin_port;
+volatile uint8_t timer5_pin_mask;
+#endif
+
+
+#if defined(__AVR_ATmega1280__)
+
+#define AVAILABLE_TONE_PINS 6
+
+// Leave timers 1, and zero to last.
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2, 3, 4, 5, 1, 0 };
+
+#elif defined(__AVR_ATmega8__)
+
+#define AVAILABLE_TONE_PINS 2
+
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2, 1 };
+
+#else
+
+#define AVAILABLE_TONE_PINS 3
+
+// Leave timer 0 to last.
+const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2, 1, 0 };
+
+#endif
+
+
+
+// Initialize our pin count
+
+uint8_t Tone::_tone_pin_count = 0;
+
+
+void Tone::begin(uint8_t tonePin)
+{
+  if (_tone_pin_count < AVAILABLE_TONE_PINS)
+  {
+    _pin = tonePin;
+    _timer = pgm_read_byte(tone_pin_to_timer_PGM + _tone_pin_count);
+    _tone_pin_count++;
+
+    // Set timer specific stuff
+    // All timers in CTC mode
+    // 8 bit timers will require changing prescalar values,
+    // whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
+    switch (_timer)
+    {
+#if !defined(__AVR_ATmega8__)
+      case 0:
+        // 8 bit timer
+        TCCR0A = 0;
+        TCCR0B = 0;
+        bitWrite(TCCR0A, WGM01, 1);
+        bitWrite(TCCR0B, CS00, 1);
+        timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer0_pin_mask = digitalPinToBitMask(_pin);
+        break;
+#endif
+
+      case 1:
+        // 16 bit timer
+        TCCR1A = 0;
+        TCCR1B = 0;
+        bitWrite(TCCR1B, WGM12, 1);
+        bitWrite(TCCR1B, CS10, 1);
+        timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer1_pin_mask = digitalPinToBitMask(_pin);
+        break;
+      case 2:
+        // 8 bit timer
+        TCCR2A = 0;
+        TCCR2B = 0;
+        bitWrite(TCCR2A, WGM21, 1);
+        bitWrite(TCCR2B, CS20, 1);
+        timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer2_pin_mask = digitalPinToBitMask(_pin);
+        break;
+
+#if defined(__AVR_ATmega1280__)
+      case 3:
+        // 16 bit timer
+        TCCR3A = 0;
+        TCCR3B = 0;
+        bitWrite(TCCR3B, WGM32, 1);
+        bitWrite(TCCR3B, CS30, 1);
+        timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer3_pin_mask = digitalPinToBitMask(_pin);
+        break;
+      case 4:
+        // 16 bit timer
+        TCCR4A = 0;
+        TCCR4B = 0;
+        bitWrite(TCCR4B, WGM42, 1);
+        bitWrite(TCCR4B, CS40, 1);
+        timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer4_pin_mask = digitalPinToBitMask(_pin);
+        break;
+      case 5:
+        // 16 bit timer
+        TCCR5A = 0;
+        TCCR5B = 0;
+        bitWrite(TCCR5B, WGM52, 1);
+        bitWrite(TCCR5B, CS50, 1);
+        timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
+        timer5_pin_mask = digitalPinToBitMask(_pin);
+        break;
+#endif
+    }
+  }
+  else
+  {
+    // disabled
+    _timer = -1;
+  }
+}
+
+
+
+// frequency (in hertz) and duration (in milliseconds).
+
+void Tone::play(uint16_t frequency, uint32_t duration)
+{
+  uint8_t prescalarbits = 0b001;
+  int32_t toggle_count = 0;
+  uint32_t ocr = 0;
+
+  if (_timer >= 0)
+  {
+    // Set the pinMode as OUTPUT
+    pinMode(_pin, OUTPUT);
+    
+    // if we are using an 8 bit timer, scan through prescalars to find the best fit
+    if (_timer == 0 || _timer == 2)
+    {
+      ocr = F_CPU / frequency / 2 - 1;
+      prescalarbits = 0b001;  // ck/1: same for both timers
+      if (ocr > 255)
+      {
+        ocr = F_CPU / frequency / 2 / 8 - 1;
+        prescalarbits = 0b010;  // ck/8: same for both timers
+
+        if (_timer == 2 && ocr > 255)
+        {
+          ocr = F_CPU / frequency / 2 / 32 - 1;
+          prescalarbits = 0b011;
+        }
+
+        if (ocr > 255)
+        {
+          ocr = F_CPU / frequency / 2 / 64 - 1;
+          prescalarbits = _timer == 0 ? 0b011 : 0b100;
+
+          if (_timer == 2 && ocr > 255)
+          {
+            ocr = F_CPU / frequency / 2 / 128 - 1;
+            prescalarbits = 0b101;
+          }
+
+          if (ocr > 255)
+          {
+            ocr = F_CPU / frequency / 2 / 256 - 1;
+            prescalarbits = _timer == 0 ? 0b100 : 0b110;
+            if (ocr > 255)
+            {
+              // can't do any better than /1024
+              ocr = F_CPU / frequency / 2 / 1024 - 1;
+              prescalarbits = _timer == 0 ? 0b101 : 0b111;
+            }
+          }
+        }
+      }
+
+#if !defined(__AVR_ATmega8__)
+      if (_timer == 0)
+        TCCR0B = (TCCR0B & 0b11111000) | prescalarbits;
+      else
+#endif
+        TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
+    }
+    else
+    {
+      // two choices for the 16 bit timers: ck/1 or ck/64
+      ocr = F_CPU / frequency / 2 - 1;
+
+      prescalarbits = 0b001;
+      if (ocr > 0xffff)
+      {
+        ocr = F_CPU / frequency / 2 / 64 - 1;
+        prescalarbits = 0b011;
+      }
+
+      if (_timer == 1)
+        TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
+#if defined(__AVR_ATmega1280__)
+      else if (_timer == 3)
+        TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
+      else if (_timer == 4)
+        TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
+      else if (_timer == 5)
+        TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
+#endif
+
+    }
+    
+
+    // Calculate the toggle count
+    if (duration > 0)
+    {
+      toggle_count = 2 * frequency * duration / 1000;
+    }
+    else
+    {
+      toggle_count = -1;
+    }
+
+    // Set the OCR for the given timer,
+    // set the toggle count,
+    // then turn on the interrupts
+    switch (_timer)
+    {
+
+#if !defined(__AVR_ATmega8__)
+      case 0:
+        OCR0A = ocr;
+        timer0_toggle_count = toggle_count;
+        bitWrite(TIMSK0, OCIE0A, 1);
+        break;
+#endif
+
+      case 1:
+        OCR1A = ocr;
+        timer1_toggle_count = toggle_count;
+        bitWrite(TIMSK1, OCIE1A, 1);
+        break;
+      case 2:
+        OCR2A = ocr;
+        timer2_toggle_count = toggle_count;
+        bitWrite(TIMSK2, OCIE2A, 1);
+        break;
+
+#if defined(__AVR_ATmega1280__)
+      case 3:
+        OCR3A = ocr;
+        timer3_toggle_count = toggle_count;
+        bitWrite(TIMSK3, OCIE3A, 1);
+        break;
+      case 4:
+        OCR4A = ocr;
+        timer4_toggle_count = toggle_count;
+        bitWrite(TIMSK4, OCIE4A, 1);
+        break;
+      case 5:
+        OCR5A = ocr;
+        timer5_toggle_count = toggle_count;
+        bitWrite(TIMSK5, OCIE5A, 1);
+        break;
+#endif
+
+    }
+  }
+}
+
+
+void Tone::stop()
+{
+  switch (_timer)
+  {
+#if !defined(__AVR_ATmega8__)
+    case 0:
+      TIMSK0 &= ~(1 << OCIE0A);
+      break;
+#endif
+    case 1:
+      TIMSK1 &= ~(1 << OCIE1A);
+      break;
+    case 2:
+      TIMSK2 &= ~(1 << OCIE2A);
+      break;
+
+#if defined(__AVR_ATmega1280__)
+    case 3:
+      TIMSK3 &= ~(1 << OCIE3A);
+      break;
+    case 4:
+      TIMSK4 &= ~(1 << OCIE4A);
+      break;
+    case 5:
+      TIMSK5 &= ~(1 << OCIE5A);
+      break;
+#endif
+  }
+
+  digitalWrite(_pin, 0);
+}
+
+
+bool Tone::isPlaying(void)
+{
+  bool returnvalue = false;
+  
+  switch (_timer)
+  {
+#if !defined(__AVR_ATmega8__)
+    case 0:
+      returnvalue = (TIMSK0 & (1 << OCIE0A));
+      break;
+#endif
+
+    case 1:
+      returnvalue = (TIMSK1 & (1 << OCIE1A));
+      break;
+    case 2:
+      returnvalue = (TIMSK2 & (1 << OCIE2A));
+      break;
+
+#if defined(__AVR_ATmega1280__)
+    case 3:
+      returnvalue = (TIMSK3 & (1 << OCIE3A));
+      break;
+    case 4:
+      returnvalue = (TIMSK4 & (1 << OCIE4A));
+      break;
+    case 5:
+      returnvalue = (TIMSK5 & (1 << OCIE5A));
+      break;
+#endif
+
+  }
+  return returnvalue;
+}
+
+
+#if !defined(__AVR_ATmega8__)
+ISR(TIMER0_COMPA_vect)
+{
+  if (timer0_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer0_pin_port ^= timer0_pin_mask;
+
+    if (timer0_toggle_count > 0)
+      timer0_toggle_count--;
+  }
+  else
+  {
+    TIMSK0 &= ~(1 << OCIE0A);                 // disable the interrupt
+    *timer0_pin_port &= ~(timer0_pin_mask);   // keep pin low after stop
+  }
+}
+#endif
+
+
+ISR(TIMER1_COMPA_vect)
+{
+  if (timer1_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer1_pin_port ^= timer1_pin_mask;
+
+    if (timer1_toggle_count > 0)
+      timer1_toggle_count--;
+  }
+  else
+  {
+    TIMSK1 &= ~(1 << OCIE1A);                 // disable the interrupt
+    *timer1_pin_port &= ~(timer1_pin_mask);   // keep pin low after stop
+  }
+}
+
+
+ISR(TIMER2_COMPA_vect)
+{
+  int32_t temp_toggle_count = timer2_toggle_count;
+
+  if (temp_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer2_pin_port ^= timer2_pin_mask;
+
+    if (temp_toggle_count > 0)
+      temp_toggle_count--;
+  }
+  else
+  {
+    TIMSK2 &= ~(1 << OCIE2A);                 // disable the interrupt
+    *timer2_pin_port &= ~(timer2_pin_mask);   // keep pin low after stop
+  }
+  
+  timer2_toggle_count = temp_toggle_count;
+}
+
+
+
+#if defined(__AVR_ATmega1280__)
+
+ISR(TIMER3_COMPA_vect)
+{
+  if (timer3_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer3_pin_port ^= timer3_pin_mask;
+
+    if (timer3_toggle_count > 0)
+      timer3_toggle_count--;
+  }
+  else
+  {
+    TIMSK3 &= ~(1 << OCIE3A);                 // disable the interrupt
+    *timer3_pin_port &= ~(timer3_pin_mask);   // keep pin low after stop
+  }
+}
+
+ISR(TIMER4_COMPA_vect)
+{
+  if (timer4_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer4_pin_port ^= timer4_pin_mask;
+
+    if (timer4_toggle_count > 0)
+      timer4_toggle_count--;
+  }
+  else
+  {
+    TIMSK4 &= ~(1 << OCIE4A);                 // disable the interrupt
+    *timer4_pin_port &= ~(timer4_pin_mask);   // keep pin low after stop
+  }
+}
+
+ISR(TIMER5_COMPA_vect)
+{
+  if (timer5_toggle_count != 0)
+  {
+    // toggle the pin
+    *timer5_pin_port ^= timer5_pin_mask;
+
+    if (timer5_toggle_count > 0)
+      timer5_toggle_count--;
+  }
+  else
+  {
+    TIMSK5 &= ~(1 << OCIE5A);                 // disable the interrupt
+    *timer5_pin_port &= ~(timer5_pin_mask);   // keep pin low after stop
+  }
+}
+
+#endif
+/* $Id: Tone.h 113 2010-06-16 20:16:29Z bhagman@roguerobotics.com $
+
+  A Tone Generator Library
+
+  Written by Brett Hagman
+  http://www.roguerobotics.com/
+  bhagman@roguerobotics.com
+
+    This library is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+*************************************************/
+
+#ifndef _Tone_h
+#define _Tone_h
+
+#include <stdint.h>
+
+/*************************************************
+* Public Constants
+*************************************************/
+
+#define NOTE_B0  31
+#define NOTE_C1  33
+#define NOTE_CS1 35
+#define NOTE_D1  37
+#define NOTE_DS1 39
+#define NOTE_E1  41
+#define NOTE_F1  44
+#define NOTE_FS1 46
+#define NOTE_G1  49
+#define NOTE_GS1 52
+#define NOTE_A1  55
+#define NOTE_AS1 58
+#define NOTE_B1  62
+#define NOTE_C2  65
+#define NOTE_CS2 69
+#define NOTE_D2  73
+#define NOTE_DS2 78
+#define NOTE_E2  82
+#define NOTE_F2  87
+#define NOTE_FS2 93
+#define NOTE_G2  98
+#define NOTE_GS2 104
+#define NOTE_A2  110
+#define NOTE_AS2 117
+#define NOTE_B2  123
+#define NOTE_C3  131
+#define NOTE_CS3 139
+#define NOTE_D3  147
+#define NOTE_DS3 156
+#define NOTE_E3  165
+#define NOTE_F3  175
+#define NOTE_FS3 185
+#define NOTE_G3  196
+#define NOTE_GS3 208
+#define NOTE_A3  220
+#define NOTE_AS3 233
+#define NOTE_B3  247
+#define NOTE_C4  262
+#define NOTE_CS4 277
+#define NOTE_D4  294
+#define NOTE_DS4 311
+#define NOTE_E4  330
+#define NOTE_F4  349
+#define NOTE_FS4 370
+#define NOTE_G4  392
+#define NOTE_GS4 415
+#define NOTE_A4  440
+#define NOTE_AS4 466
+#define NOTE_B4  494
+#define NOTE_C5  523
+#define NOTE_CS5 554
+#define NOTE_D5  587
+#define NOTE_DS5 622
+#define NOTE_E5  659
+#define NOTE_F5  698
+#define NOTE_FS5 740
+#define NOTE_G5  784
+#define NOTE_GS5 831
+#define NOTE_A5  880
+#define NOTE_AS5 932
+#define NOTE_B5  988
+#define NOTE_C6  1047
+#define NOTE_CS6 1109
+#define NOTE_D6  1175
+#define NOTE_DS6 1245
+#define NOTE_E6  1319
+#define NOTE_F6  1397
+#define NOTE_FS6 1480
+#define NOTE_G6  1568
+#define NOTE_GS6 1661
+#define NOTE_A6  1760
+#define NOTE_AS6 1865
+#define NOTE_B6  1976
+#define NOTE_C7  2093
+#define NOTE_CS7 2217
+#define NOTE_D7  2349
+#define NOTE_DS7 2489
+#define NOTE_E7  2637
+#define NOTE_F7  2794
+#define NOTE_FS7 2960
+#define NOTE_G7  3136
+#define NOTE_GS7 3322
+#define NOTE_A7  3520
+#define NOTE_AS7 3729
+#define NOTE_B7  3951
+#define NOTE_C8  4186
+#define NOTE_CS8 4435
+#define NOTE_D8  4699
+#define NOTE_DS8 4978
+
+
+/*************************************************
+* Definitions
+*************************************************/
+
+class Tone
+{
+  public:
+    void begin(uint8_t tonePin);
+    bool isPlaying();
+    void play(uint16_t frequency, uint32_t duration = 0);
+    void stop();
+
+  private:
+    static uint8_t _tone_pin_count;
+    uint8_t _pin;
+    int8_t _timer;
+};
+
+#endif

File TrunetClock.cpp

 #include "HT1632C/HT1632C.h"
 #include "TrunetClock.h"
 #include "AlarmClock.h"
-#include "Sound.h"
 #include "Buttons.h"
 #include "AppLife.h"
 #include "AppDemo.h"

File trunetclock-main.cpp

 #include <WProgram.h>
+#include "Tone/Tone.h"
 //#include <stdio.h>
 //#include "DS1307/DS1307.h" 	// definition of RTC (where params are saved);
 #include "HT1632C/HT1632C.h"
 	trunetClock.readMessageFromMemory();
 
 	trunetClock.initQuotesFromMemory();
-
-	//attachInterrupt(2, irReceiverISR, LOW);
-
-//	soundAlarm();
 }
 
 void loop()
 {
 	checkButtons();
 
-	//checkIrCommands();
-
 	alarmClock.checkAlarm();
 
 	alarmClock.getTimeFromRTC();