Vadim Artamonov / Mbed 2 deprecated MidiPlayerExample

Dependencies:   MIDISongPlayer mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SongPlayer.h"
00003 #include "sound.h" // test sound
00004 
00005 // Song test program - plays a MIDI song using PWM and timer interrupts
00006 // based on http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
00007 // can be used to play a song, if you have the MIDI notes sequence
00008 
00009 
00010 
00011                     
00012 DigitalOut led1(LED1);
00013 
00014 int main()
00015 {
00016 
00017 // setup instance of new SongPlayer class, mySpeaker using pin D9
00018 // the pin must be a PWM output pin
00019     SongPlayer mySpeaker(D9);
00020 // Start song and return once playing starts
00021     mySpeaker.PlaySong(score3);
00022     // loops forever while song continues to play to end using interrupts
00023     int cnt=0;
00024     while(1) {
00025         led1 = !led1;
00026         wait(.1);
00027         cnt++;
00028         if (cnt>100) mySpeaker.StopPlay(); // play 10 second, then stop
00029     }
00030 }