
ECE 4180 Final Project
Speaker.h@3:660252b9fa29, 2018-12-12 (annotated)
- Committer:
- amitchell41
- Date:
- Wed Dec 12 17:11:24 2018 +0000
- Revision:
- 3:660252b9fa29
Final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amitchell41 | 3:660252b9fa29 | 1 | #include "mbed.h" |
amitchell41 | 3:660252b9fa29 | 2 | // a new class to play a note on Speaker based on PwmOut class |
amitchell41 | 3:660252b9fa29 | 3 | class Speaker |
amitchell41 | 3:660252b9fa29 | 4 | { |
amitchell41 | 3:660252b9fa29 | 5 | public: |
amitchell41 | 3:660252b9fa29 | 6 | Speaker(PinName pin) : _pin(pin) { |
amitchell41 | 3:660252b9fa29 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
amitchell41 | 3:660252b9fa29 | 8 | } |
amitchell41 | 3:660252b9fa29 | 9 | // class method to play a note based on PwmOut class |
amitchell41 | 3:660252b9fa29 | 10 | void PlayNote(float frequency, float duration, float volume) { |
amitchell41 | 3:660252b9fa29 | 11 | _pin.period(1.0/frequency); |
amitchell41 | 3:660252b9fa29 | 12 | _pin = volume/2.0; |
amitchell41 | 3:660252b9fa29 | 13 | wait(duration); |
amitchell41 | 3:660252b9fa29 | 14 | _pin = 0.0; |
amitchell41 | 3:660252b9fa29 | 15 | } |
amitchell41 | 3:660252b9fa29 | 16 | |
amitchell41 | 3:660252b9fa29 | 17 | private: |
amitchell41 | 3:660252b9fa29 | 18 | PwmOut _pin; |
amitchell41 | 3:660252b9fa29 | 19 | }; |