Sound update
Dependencies: 4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed
Speaker.h@11:e00a208bd85a, 22 months ago (annotated)
- Committer:
- jstephens78
- Date:
- Tue Nov 29 23:05:30 2022 +0000
- Revision:
- 11:e00a208bd85a
- Child:
- 26:163d7ca8c42d
Update speaker thread. Project now builds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jstephens78 | 11:e00a208bd85a | 1 | #include "mbed.h" |
jstephens78 | 11:e00a208bd85a | 2 | // new class to play a note on Speaker based on PwmOut class |
jstephens78 | 11:e00a208bd85a | 3 | class Speaker |
jstephens78 | 11:e00a208bd85a | 4 | { |
jstephens78 | 11:e00a208bd85a | 5 | public: |
jstephens78 | 11:e00a208bd85a | 6 | Speaker(PinName pin) : _pin(pin) |
jstephens78 | 11:e00a208bd85a | 7 | { |
jstephens78 | 11:e00a208bd85a | 8 | // _pin(pin) means pass pin to the Speaker Constructor |
jstephens78 | 11:e00a208bd85a | 9 | } |
jstephens78 | 11:e00a208bd85a | 10 | // class method to play a note based on PwmOut class |
jstephens78 | 11:e00a208bd85a | 11 | void PlayNote(float frequency, float duration, float volume) |
jstephens78 | 11:e00a208bd85a | 12 | { |
jstephens78 | 11:e00a208bd85a | 13 | _pin.period(1.0/frequency); |
jstephens78 | 11:e00a208bd85a | 14 | _pin = volume/2.0; |
jstephens78 | 11:e00a208bd85a | 15 | wait(duration); |
jstephens78 | 11:e00a208bd85a | 16 | _pin = 0.0; |
jstephens78 | 11:e00a208bd85a | 17 | } |
jstephens78 | 11:e00a208bd85a | 18 | |
jstephens78 | 11:e00a208bd85a | 19 | private: |
jstephens78 | 11:e00a208bd85a | 20 | PwmOut _pin; |
jstephens78 | 11:e00a208bd85a | 21 | }; |