P2-2 Harris Barton
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Speaker.h@3:e2fb359d6545, 2020-11-25 (annotated)
- Committer:
- hbarton7
- Date:
- Wed Nov 25 01:17:39 2020 +0000
- Revision:
- 3:e2fb359d6545
P2-2 Harris Barton;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hbarton7 | 3:e2fb359d6545 | 1 | #include "mbed.h" |
hbarton7 | 3:e2fb359d6545 | 2 | // new class to play a note on Speaker based on PwmOut class |
hbarton7 | 3:e2fb359d6545 | 3 | class Speaker |
hbarton7 | 3:e2fb359d6545 | 4 | { |
hbarton7 | 3:e2fb359d6545 | 5 | public: |
hbarton7 | 3:e2fb359d6545 | 6 | Speaker(PinName pin) : _pin(pin) { |
hbarton7 | 3:e2fb359d6545 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
hbarton7 | 3:e2fb359d6545 | 8 | } |
hbarton7 | 3:e2fb359d6545 | 9 | // class method to play a note based on PwmOut class |
hbarton7 | 3:e2fb359d6545 | 10 | void PlayNote(float frequency, float duration, float volume) { |
hbarton7 | 3:e2fb359d6545 | 11 | _pin.period(1.0/frequency); |
hbarton7 | 3:e2fb359d6545 | 12 | _pin = volume/2.0; |
hbarton7 | 3:e2fb359d6545 | 13 | wait(duration); |
hbarton7 | 3:e2fb359d6545 | 14 | _pin = 0.0; |
hbarton7 | 3:e2fb359d6545 | 15 | } |
hbarton7 | 3:e2fb359d6545 | 16 | |
hbarton7 | 3:e2fb359d6545 | 17 | private: |
hbarton7 | 3:e2fb359d6545 | 18 | PwmOut _pin; |
hbarton7 | 3:e2fb359d6545 | 19 | }; |