Words
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed
Speaker.h@1:3cf69c15ada7, 2017-03-02 (annotated)
- Committer:
- apaks180
- Date:
- Thu Mar 02 19:45:19 2017 +0000
- Revision:
- 1:3cf69c15ada7
- Parent:
- 0:0072ee664a9b
Final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apaks180 | 0:0072ee664a9b | 1 | #include "mbed.h" |
apaks180 | 0:0072ee664a9b | 2 | // new class to play a note on Speaker based on PwmOut class |
apaks180 | 0:0072ee664a9b | 3 | class Speaker |
apaks180 | 0:0072ee664a9b | 4 | { |
apaks180 | 0:0072ee664a9b | 5 | public: |
apaks180 | 0:0072ee664a9b | 6 | Speaker(PinName pin) : _pin(pin) { |
apaks180 | 0:0072ee664a9b | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
apaks180 | 0:0072ee664a9b | 8 | } |
apaks180 | 0:0072ee664a9b | 9 | // class method to play a note based on PwmOut class |
apaks180 | 0:0072ee664a9b | 10 | void PlayNote(float frequency, float duration, float volume) { |
apaks180 | 0:0072ee664a9b | 11 | _pin.period(1.0/frequency); |
apaks180 | 0:0072ee664a9b | 12 | _pin = volume/2.0; |
apaks180 | 0:0072ee664a9b | 13 | wait(duration); |
apaks180 | 0:0072ee664a9b | 14 | _pin = 0.0; |
apaks180 | 0:0072ee664a9b | 15 | } |
apaks180 | 0:0072ee664a9b | 16 | |
apaks180 | 0:0072ee664a9b | 17 | private: |
apaks180 | 0:0072ee664a9b | 18 | PwmOut _pin; |
apaks180 | 0:0072ee664a9b | 19 | }; |