
Demo for new class to play a note on a speaker using a PWM output See http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
main.cpp@0:b2fdf3770282, 2013-01-20 (annotated)
- Committer:
- 4180_1
- Date:
- Sun Jan 20 03:02:37 2013 +0000
- Revision:
- 0:b2fdf3770282
- Child:
- 1:2e6ea42675c7
- Child:
- 2:68eee0fb2026
ver 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:b2fdf3770282 | 1 | #include "mbed.h" |
4180_1 | 0:b2fdf3770282 | 2 | #include "Speaker.h" |
4180_1 | 0:b2fdf3770282 | 3 | |
4180_1 | 0:b2fdf3770282 | 4 | // Speaker test program - euro police style siren now using new Speaker class method |
4180_1 | 0:b2fdf3770282 | 5 | // for documentation see http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/ |
4180_1 | 0:b2fdf3770282 | 6 | // can also be used to play a song, if you have the notes and durations |
4180_1 | 0:b2fdf3770282 | 7 | // for musical note frequencies see http://en.wikipedia.org/wiki/Piano_key_frequencies |
4180_1 | 0:b2fdf3770282 | 8 | |
4180_1 | 0:b2fdf3770282 | 9 | int main() |
4180_1 | 0:b2fdf3770282 | 10 | { |
4180_1 | 0:b2fdf3770282 | 11 | // setup instance of new Speaker class, mySpeaker using pin 21 |
4180_1 | 0:b2fdf3770282 | 12 | // the pin must be a PWM output pin |
4180_1 | 0:b2fdf3770282 | 13 | Speaker mySpeaker(p21); |
4180_1 | 0:b2fdf3770282 | 14 | // loops forever playing two notes on speaker |
4180_1 | 0:b2fdf3770282 | 15 | while(1) { |
4180_1 | 0:b2fdf3770282 | 16 | mySpeaker.PlayNote(969.0,0.5,0.5); |
4180_1 | 0:b2fdf3770282 | 17 | mySpeaker.PlayNote(800.0,0.5,0.5); |
4180_1 | 0:b2fdf3770282 | 18 | } |
4180_1 | 0:b2fdf3770282 | 19 | } |