Speaker class file
Dependents: musicplayer Beat_Demo_full_full jumper mbed_AOS_proj ... more
Speaker.h@0:41292907c9cb, 2013-02-12 (annotated)
- Committer:
- zchen311
- Date:
- Tue Feb 12 06:24:02 2013 +0000
- Revision:
- 0:41292907c9cb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zchen311 | 0:41292907c9cb | 1 | #include "mbed.h" |
zchen311 | 0:41292907c9cb | 2 | // new class to play a note on Speaker based on PwmOut class |
zchen311 | 0:41292907c9cb | 3 | class Speaker |
zchen311 | 0:41292907c9cb | 4 | { |
zchen311 | 0:41292907c9cb | 5 | public: |
zchen311 | 0:41292907c9cb | 6 | Speaker(PinName pin) : _pin(pin) { |
zchen311 | 0:41292907c9cb | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
zchen311 | 0:41292907c9cb | 8 | } |
zchen311 | 0:41292907c9cb | 9 | // class method to play a note based on PwmOut class |
zchen311 | 0:41292907c9cb | 10 | void PlayNote(float frequency, float duration, float volume) { |
zchen311 | 0:41292907c9cb | 11 | _pin.period(1.0/frequency); |
zchen311 | 0:41292907c9cb | 12 | _pin = volume/2.0; |
zchen311 | 0:41292907c9cb | 13 | wait(duration); |
zchen311 | 0:41292907c9cb | 14 | _pin = 0.0; |
zchen311 | 0:41292907c9cb | 15 | } |
zchen311 | 0:41292907c9cb | 16 | |
zchen311 | 0:41292907c9cb | 17 | private: |
zchen311 | 0:41292907c9cb | 18 | PwmOut _pin; |
zchen311 | 0:41292907c9cb | 19 | }; |