Sound update
Dependencies: 4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed
Speaker.h@26:163d7ca8c42d, 22 months ago (annotated)
- Committer:
- jsanchez307
- Date:
- Thu Dec 08 02:12:14 2022 +0000
- Revision:
- 26:163d7ca8c42d
- Parent:
- 11:e00a208bd85a
- Child:
- 27:a09981ebd532
No speaker. LED works for Tetris by going through RGB one at a time. LCD successfully clears the screen after Tetris is in Game Over and goes to the Menu.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jsanchez307 | 26:163d7ca8c42d | 1 | //#ifndef __SPEAKER.H |
jsanchez307 | 26:163d7ca8c42d | 2 | //#define __SPEAKER.H |
jsanchez307 | 26:163d7ca8c42d | 3 | |
jstephens78 | 11:e00a208bd85a | 4 | #include "mbed.h" |
jstephens78 | 11:e00a208bd85a | 5 | // new class to play a note on Speaker based on PwmOut class |
jstephens78 | 11:e00a208bd85a | 6 | class Speaker |
jstephens78 | 11:e00a208bd85a | 7 | { |
jstephens78 | 11:e00a208bd85a | 8 | public: |
jstephens78 | 11:e00a208bd85a | 9 | Speaker(PinName pin) : _pin(pin) |
jstephens78 | 11:e00a208bd85a | 10 | { |
jstephens78 | 11:e00a208bd85a | 11 | // _pin(pin) means pass pin to the Speaker Constructor |
jstephens78 | 11:e00a208bd85a | 12 | } |
jstephens78 | 11:e00a208bd85a | 13 | // class method to play a note based on PwmOut class |
jstephens78 | 11:e00a208bd85a | 14 | void PlayNote(float frequency, float duration, float volume) |
jstephens78 | 11:e00a208bd85a | 15 | { |
jstephens78 | 11:e00a208bd85a | 16 | _pin.period(1.0/frequency); |
jstephens78 | 11:e00a208bd85a | 17 | _pin = volume/2.0; |
jstephens78 | 11:e00a208bd85a | 18 | wait(duration); |
jstephens78 | 11:e00a208bd85a | 19 | _pin = 0.0; |
jstephens78 | 11:e00a208bd85a | 20 | } |
jstephens78 | 11:e00a208bd85a | 21 | |
jstephens78 | 11:e00a208bd85a | 22 | private: |
jstephens78 | 11:e00a208bd85a | 23 | PwmOut _pin; |
jsanchez307 | 26:163d7ca8c42d | 24 | }; |
jsanchez307 | 26:163d7ca8c42d | 25 | |
jsanchez307 | 26:163d7ca8c42d | 26 | //#endif |