Starter code for Georgia Tech ECE 2036 Summer 2014 Lab 2
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Speaker.h@2:6163865f5ce3, 2014-06-20 (annotated)
- Committer:
- jlind6
- Date:
- Fri Jun 20 15:22:28 2014 +0000
- Revision:
- 2:6163865f5ce3
- Parent:
- 0:356124c0bafc
(Typo) On line 135, changed a vy to a vx.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jlind6 | 0:356124c0bafc | 1 | #include "mbed.h" |
jlind6 | 0:356124c0bafc | 2 | // new class to play a note on Speaker based on PwmOut class |
jlind6 | 0:356124c0bafc | 3 | #ifndef _SPEAKER_H |
jlind6 | 0:356124c0bafc | 4 | #define _SPEAKER_H |
jlind6 | 0:356124c0bafc | 5 | class Speaker |
jlind6 | 0:356124c0bafc | 6 | { |
jlind6 | 0:356124c0bafc | 7 | public: |
jlind6 | 0:356124c0bafc | 8 | Speaker(PinName pin) : _pin(pin) { |
jlind6 | 0:356124c0bafc | 9 | // _pin(pin) means pass pin to the Speaker Constructor |
jlind6 | 0:356124c0bafc | 10 | } |
jlind6 | 0:356124c0bafc | 11 | // class method to play a note based on PwmOut class |
jlind6 | 0:356124c0bafc | 12 | void PlayNote(float frequency, float duration, float volume) { |
jlind6 | 0:356124c0bafc | 13 | _pin.period(1.0/frequency); |
jlind6 | 0:356124c0bafc | 14 | _pin = volume/2.0; |
jlind6 | 0:356124c0bafc | 15 | wait(duration); |
jlind6 | 0:356124c0bafc | 16 | _pin = 0.0; |
jlind6 | 0:356124c0bafc | 17 | } |
jlind6 | 0:356124c0bafc | 18 | |
jlind6 | 0:356124c0bafc | 19 | private: |
jlind6 | 0:356124c0bafc | 20 | PwmOut _pin; |
jlind6 | 0:356124c0bafc | 21 | }; |
jlind6 | 0:356124c0bafc | 22 | |
jlind6 | 0:356124c0bafc | 23 | #endif // _SPEAKER_H |