Bing Xian Lim / Mbed 2 deprecated ECE4180FinalProjectRTOS

Dependencies:   SDFileSystem mbed-rtos mbed

Fork of ECE4180Lab4 by Frank Zhou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SongPlayer.h Source File

SongPlayer.h

00001 #include "mbed.h"
00002 #include <rtos.h>
00003 // new class to play a note on Speaker based on PwmOut class
00004 class SongPlayer {
00005 public:
00006     SongPlayer(PinName pin) : _pin(pin) {
00007     // _pin(pin) means pass pin to the constructor
00008     }
00009     
00010     // class method to play a note based on PwmOut class
00011     void PlaySong(float frequency[], float duration[], float volume = 1.0) {
00012         notecount = 0;
00013         while (duration[notecount] != 0.0) {
00014             _pin.period(1.0 / frequency[notecount]);
00015             _pin = volume / 2.0;
00016             Thread::wait((int) (duration[notecount++] * 1000));
00017         }
00018         _pin = 0.0;
00019     }
00020     
00021 private:
00022     PwmOut _pin;
00023     int notecount;
00024     float vol;
00025     float * frequencyptr;
00026     float * durationptr;
00027 };