MIDISongPlayer library usage example

Dependencies:   MIDISongPlayer mbed

main.cpp

Committer:
vart
Date:
2015-11-02
Revision:
0:43695a918606

File content as of revision 0:43695a918606:

#include "mbed.h"
#include "SongPlayer.h"
#include "sound.h" // test sound

// Song test program - plays a MIDI song using PWM and timer interrupts
// based on http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
// can be used to play a song, if you have the MIDI notes sequence



                    
DigitalOut led1(LED1);

int main()
{

// setup instance of new SongPlayer class, mySpeaker using pin D9
// the pin must be a PWM output pin
    SongPlayer mySpeaker(D9);
// Start song and return once playing starts
    mySpeaker.PlaySong(score3);
    // loops forever while song continues to play to end using interrupts
    int cnt=0;
    while(1) {
        led1 = !led1;
        wait(.1);
        cnt++;
        if (cnt>100) mySpeaker.StopPlay(); // play 10 second, then stop
    }
}