alarm
Dependencies: PinDetect SDFileSystem mbed wave_player
Speaker.h@0:a2ded96ce136, 2014-12-02 (annotated)
- Committer:
- jhawkins38
- Date:
- Tue Dec 02 15:21:13 2014 +0000
- Revision:
- 0:a2ded96ce136
for alarm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhawkins38 | 0:a2ded96ce136 | 1 | #include "mbed.h" |
jhawkins38 | 0:a2ded96ce136 | 2 | // a new class to play a note on Speaker based on PwmOut class |
jhawkins38 | 0:a2ded96ce136 | 3 | class Speaker |
jhawkins38 | 0:a2ded96ce136 | 4 | { |
jhawkins38 | 0:a2ded96ce136 | 5 | public: |
jhawkins38 | 0:a2ded96ce136 | 6 | Speaker(PinName pin) : _pin(pin) { |
jhawkins38 | 0:a2ded96ce136 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
jhawkins38 | 0:a2ded96ce136 | 8 | } |
jhawkins38 | 0:a2ded96ce136 | 9 | // class method to play a note based on PwmOut class |
jhawkins38 | 0:a2ded96ce136 | 10 | void PlayNote(float frequency, float duration, float volume) { |
jhawkins38 | 0:a2ded96ce136 | 11 | _pin.period(1.0/frequency); |
jhawkins38 | 0:a2ded96ce136 | 12 | _pin = volume/2.0; |
jhawkins38 | 0:a2ded96ce136 | 13 | wait(duration); |
jhawkins38 | 0:a2ded96ce136 | 14 | _pin = 0.0; |
jhawkins38 | 0:a2ded96ce136 | 15 | } |
jhawkins38 | 0:a2ded96ce136 | 16 | |
jhawkins38 | 0:a2ded96ce136 | 17 | private: |
jhawkins38 | 0:a2ded96ce136 | 18 | PwmOut _pin; |
jhawkins38 | 0:a2ded96ce136 | 19 | }; |