![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
thermostat
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed
Fork of mythermostat by
Speaker.h@2:58d85409f7ff, 2013-01-31 (annotated)
- Committer:
- 4180_1
- Date:
- Thu Jan 31 03:15:20 2013 +0000
- Revision:
- 2:58d85409f7ff
ver 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 2:58d85409f7ff | 1 | #include "mbed.h" |
4180_1 | 2:58d85409f7ff | 2 | // new class to play a note on Speaker based on PwmOut class |
4180_1 | 2:58d85409f7ff | 3 | class Speaker |
4180_1 | 2:58d85409f7ff | 4 | { |
4180_1 | 2:58d85409f7ff | 5 | public: |
4180_1 | 2:58d85409f7ff | 6 | Speaker(PinName pin) : _pin(pin) { |
4180_1 | 2:58d85409f7ff | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
4180_1 | 2:58d85409f7ff | 8 | } |
4180_1 | 2:58d85409f7ff | 9 | // class method to play a note based on PwmOut class |
4180_1 | 2:58d85409f7ff | 10 | void PlayNote(float frequency, float duration, float volume) { |
4180_1 | 2:58d85409f7ff | 11 | _pin.period(1.0/frequency); |
4180_1 | 2:58d85409f7ff | 12 | _pin = volume/2.0; |
4180_1 | 2:58d85409f7ff | 13 | wait(duration); |
4180_1 | 2:58d85409f7ff | 14 | _pin = 0.0; |
4180_1 | 2:58d85409f7ff | 15 | } |
4180_1 | 2:58d85409f7ff | 16 | |
4180_1 | 2:58d85409f7ff | 17 | private: |
4180_1 | 2:58d85409f7ff | 18 | PwmOut _pin; |
4180_1 | 2:58d85409f7ff | 19 | }; |