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/

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Speaker.h"
00003 
00004 // Speaker test program - euro police style siren now using new Speaker class method
00005 // for documentation see http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
00006 // can also be used to play a song, if you have all of the notes and durations
00007 // for musical note frequencies see http://en.wikipedia.org/wiki/Piano_key_frequencies
00008 
00009 int main()
00010 {
00011 // setup instance of new Speaker class, mySpeaker using pin 21
00012 // the pin must be a PWM output pin
00013     Speaker mySpeaker(p21);
00014     // loops forever playing two notes on speaker
00015     while(1) {
00016         mySpeaker.PlayNote(969.0,0.5,0.5);
00017         mySpeaker.PlayNote(800.0,0.5,0.5);
00018     }
00019 }
00020