![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Bluetooth
Dependencies: 4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player
Speaker.h@4:d8ec758304be, 21 months ago (annotated)
- Committer:
- jwalker366
- Date:
- Mon Dec 05 04:21:11 2022 +0000
- Revision:
- 4:d8ec758304be
- Parent:
- 3:2499b6bda80f
review tomorrow;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jwalker366 | 3:2499b6bda80f | 1 | #ifndef SPEAKER_H |
jwalker366 | 3:2499b6bda80f | 2 | #define SPEAKER_H |
jwalker366 | 3:2499b6bda80f | 3 | #include "mbed.h" |
jwalker366 | 3:2499b6bda80f | 4 | |
jwalker366 | 3:2499b6bda80f | 5 | // new class to play a note on Speaker based on PwmOut class |
jwalker366 | 3:2499b6bda80f | 6 | class Speaker |
jwalker366 | 3:2499b6bda80f | 7 | { |
jwalker366 | 3:2499b6bda80f | 8 | public: |
jwalker366 | 3:2499b6bda80f | 9 | Speaker(PinName pin) : _pin(pin) { |
jwalker366 | 3:2499b6bda80f | 10 | // _pin(pin) means pass pin to the Speaker Constructor |
jwalker366 | 3:2499b6bda80f | 11 | } |
jwalker366 | 3:2499b6bda80f | 12 | // class method to play a note based on PwmOut class |
jwalker366 | 3:2499b6bda80f | 13 | void PlayNote(float frequency, float duration, float volume) { |
jwalker366 | 3:2499b6bda80f | 14 | _pin.period(1.0/frequency); |
jwalker366 | 3:2499b6bda80f | 15 | _pin = volume/2.0; |
jwalker366 | 3:2499b6bda80f | 16 | wait(duration); |
jwalker366 | 3:2499b6bda80f | 17 | _pin = 0.0; |
jwalker366 | 3:2499b6bda80f | 18 | } |
jwalker366 | 3:2499b6bda80f | 19 | |
jwalker366 | 3:2499b6bda80f | 20 | private: |
jwalker366 | 3:2499b6bda80f | 21 | PwmOut _pin; |
jwalker366 | 3:2499b6bda80f | 22 | }; |
jwalker366 | 3:2499b6bda80f | 23 | #endif |