hack gt final code
Dependencies: 4DGL-uLCD-SE BMP085 PinDetect SDFileSystem mbed wave_player
Speaker.h@14:23390a020d1c, 2016-09-28 (annotated)
- Committer:
- otis22894
- Date:
- Wed Sep 28 00:16:16 2016 +0000
- Revision:
- 14:23390a020d1c
- Parent:
- 4:d29e7e826c42
initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
otis22894 | 4:d29e7e826c42 | 1 | #include "mbed.h" |
otis22894 | 4:d29e7e826c42 | 2 | // new class to play a note on Speaker based on PwmOut class |
otis22894 | 4:d29e7e826c42 | 3 | class Speaker |
otis22894 | 4:d29e7e826c42 | 4 | { |
otis22894 | 4:d29e7e826c42 | 5 | public: |
otis22894 | 4:d29e7e826c42 | 6 | Speaker(PinName pin) : _pin(pin) { |
otis22894 | 4:d29e7e826c42 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
otis22894 | 4:d29e7e826c42 | 8 | } |
otis22894 | 4:d29e7e826c42 | 9 | // class method to play a note based on PwmOut class |
otis22894 | 4:d29e7e826c42 | 10 | void PlayNote(float frequency, float duration, float volume) { |
otis22894 | 4:d29e7e826c42 | 11 | _pin.period(1.0/frequency); |
otis22894 | 4:d29e7e826c42 | 12 | _pin = volume/2.0; |
otis22894 | 4:d29e7e826c42 | 13 | wait(duration); |
otis22894 | 4:d29e7e826c42 | 14 | _pin = 0.0; |
otis22894 | 4:d29e7e826c42 | 15 | } |
otis22894 | 4:d29e7e826c42 | 16 | |
otis22894 | 4:d29e7e826c42 | 17 | private: |
otis22894 | 4:d29e7e826c42 | 18 | PwmOut _pin; |
otis22894 | 4:d29e7e826c42 | 19 | }; |