47 #include "util/delay.h"
68 ENTER_DDR |= (1 << PE7);
69 ENTER_PUR |= (1 << PE7);
72 BEEP_DDR |= (1 << BEEP_BIT);
76 BEEP_PIN |= (1 << BEEP_BIT);
84 BEEP_PIN |= (1 << BEEP_BIT);
91 BEEP_PORT &= ~(1 << BEEP_BIT);
92 ENTER_PUR &= ~(1 << PE7);
103 #define BASE 31250/2 //up one octave
130 #define TONE_LENGTH 60
134 static uint8_t tuneindex=0;
135 static uint8_t pictures[] PROGMEM = {G4,4, F4,4, AS4,4, C5,2, F5,2, D5,4, C5,2, F5,2, D5,4, AS4,4, C5,4, G4,4, F4,4, 0xff};
136 static uint8_t axel[] PROGMEM = {FS4,2, NONE,2, A4,3, FS4,2, FS4,1, B4,2, FS4,2, E4,2, FS4,2, NONE,2, CS5,3, FS4,2, FS4,1, D5,2, CS5,2, A4,2, FS4,2, CS5,2, FS5,2, FS4,1, E4,2, E4,1, CS4,2, GS4,2, FS4,6, 0xff};
137 static uint8_t sandman1[] PROGMEM = {F4,2, G4,2, B4,4, A4,10, B4,2, B4,2, A4,2, B4,12, 0xff};
138 static uint8_t sandman2[] PROGMEM = {C4,2, E4,2, G4,2, B4,2, A4,2, G4,2, E4,2, C4,2, D4,2, F4,2, A4,2, C5,2, B4,8, 0xff};
139 static uint8_t furelise[] PROGMEM = {E5,1, DS5,1, E5,1, DS5,1, E5,1, B4,1, D5,1, E5,1, A4,2, NONE,1, C4,1, E4,1, A4,1, B4,2, NONE,1, E4,1, GS4,1, B4,1, C5,2, 0xff};
141 static volatile uint8_t icnt,tone;
143 #include <avr/interrupt.h>
146 if (tone == NONE) icnt = 0;
147 else if (icnt++ >= tone)
149 BEEP_PIN |= (1 << BEEP_BIT);
154 void play_ringtone(
void)
159 switch (tuneindex++) {
160 case 1 :
beep();
return;
161 case 2 :noteptr=sandman1;
break;
162 case 3 :noteptr=furelise;
break;
163 case 4 :noteptr=sandman2;
break;
164 case 5 :noteptr=axel;
break;
165 default:noteptr=pictures;tuneindex=1;
break;
169 ENTER_DDR |= (1 << PE7);
170 ENTER_PUR |= (1 << PE7);
173 BEEP_DDR |= (1 << BEEP_BIT);
183 TIMSK0 |= _BV(TOIE0);
187 tone=pgm_read_byte(noteptr++);
188 if (tone==0xff)
break;
189 for (i = pgm_read_byte(noteptr++);i > 0; i--) _delay_us(1000UL*TONE_LENGTH);
190 tone = NONE;_delay_us(1000UL*TONE_GAP);
194 TIMSK0 &= ~_BV(TOIE0);
195 BEEP_PORT &= ~(1 << BEEP_BIT);
196 ENTER_PUR &= ~(1 << PE7);