Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed-rtos mbed
Fork of ECE4180Lab4 by
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 };
Generated on Thu Jul 21 2022 06:39:39 by
1.7.2
