awef
Fork of Speaker by
Revision 1:bd28eb0ec6f8, committed 2015-12-08
- Comitter:
- UnitedHolmes
- Date:
- Tue Dec 08 00:43:32 2015 +0000
- Parent:
- 0:41292907c9cb
- Commit message:
- latest edit;
Changed in this revision
Speaker.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 41292907c9cb -r bd28eb0ec6f8 Speaker.h --- a/Speaker.h Tue Feb 12 06:24:02 2013 +0000 +++ b/Speaker.h Tue Dec 08 00:43:32 2015 +0000 @@ -7,11 +7,31 @@ // _pin(pin) means pass pin to the Speaker Constructor } // class method to play a note based on PwmOut class - void PlayNote(float frequency, float duration, float volume) { - _pin.period(1.0/frequency); + void PlayNote(float frequency, float frequency2, float duration, float volume) { + if (frequency == 0) { + _pin.period(1.0/frequency2); + _pin = volume/2.0; + wait(duration); + } + else if(frequency2 == 0) { + _pin.period(1.0/frequency); + _pin = volume/2.0; + wait(duration); + } + else { + _pin.period(1.0/frequency); + _pin = volume/2.0; + wait(.008); + _pin = 0.0; + _pin.period(1.0/frequency2); _pin = volume/2.0; - wait(duration); - _pin = 0.0; + wait(.008); + } + } + + void StopPlaying() { + _pin = 0; + wait(0.001); } private: