Skip to content
Newer
Older
100644 62 lines (51 sloc) 1.57 KB
d1f8030 @perjg Initial commit
perjg authored
1 /*
2 * VFD Modular Clock
3 * (C) 2011 Akafugu Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 *
14 */
15
16 #include "piezo.h"
17
18 #include <avr/pgmspace.h>
19 #include <util/delay.h>
20
db5a4bc @perjg Added volume setting for alarm
perjg authored
21 extern uint8_t g_volume;
22
d1f8030 @perjg Initial commit
perjg authored
23 // pizeo code from: https://github.com/adafruit/Ice-Tube-Clock
24 void piezo_init(void) {
25 PEZ_PORT &= ~_BV(PEZ1) & ~_BV(PEZ2);
26 PEZ_DDR |= _BV(PEZ1) | _BV(PEZ2);
27 TCCR1A = _BV(COM1B1) | _BV(COM1B0) | _BV(WGM11);
28 TCCR1B = _BV(WGM13) | _BV(WGM12);
29
db5a4bc @perjg Added volume setting for alarm
perjg authored
30 if (g_volume) // high volume
d1f8030 @perjg Initial commit
perjg authored
31 TCCR1A |= _BV(COM1A1);
32
33 // start at 4khz: 250 * 8 multiplier * 4000 = 8mhz
34 ICR1 = 250;
35 OCR1B = OCR1A = ICR1 / 2;
36 }
37
38 void beep(uint16_t freq, uint8_t times) {
39 // set the PWM output to match the desired frequency
40 ICR1 = (F_CPU/8)/freq;
41 // we want 50% duty cycle square wave
42 OCR1A = OCR1B = ICR1/2;
43
44 while (times--) {
45 TCCR1B |= _BV(CS11); // turn it on!
46 // beeps are 200ms long on
47 _delay_ms(75);
48 TCCR1B &= ~_BV(CS11); // turn it off!
49 PEZ_PORT &= ~_BV(PEZ1) & ~_BV(PEZ2);
50 // beeps are 200ms long off
51 _delay_ms(75);
52 }
53 // turn speaker off
54 PEZ_PORT &= ~_BV(PEZ1) & ~_BV(PEZ2);
55 }
56
57 void alarm(void)
58 {
59 beep(500, 1);
60 }
61
Something went wrong with that request. Please try again.