Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed HC_SR04_Ultrasonic_Library
Speaker.h@0:0c8930416cda, 2021-03-06 (annotated)
- Committer:
- glanier9
- Date:
- Sat Mar 06 18:40:19 2021 +0000
- Revision:
- 0:0c8930416cda
Final version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| glanier9 | 0:0c8930416cda | 1 | #include "mbed.h" |
| glanier9 | 0:0c8930416cda | 2 | // a new class to play a note on Speaker based on PwmOut class |
| glanier9 | 0:0c8930416cda | 3 | class Speaker |
| glanier9 | 0:0c8930416cda | 4 | { |
| glanier9 | 0:0c8930416cda | 5 | public: |
| glanier9 | 0:0c8930416cda | 6 | Speaker(PinName pin) : _pin(pin) { |
| glanier9 | 0:0c8930416cda | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
| glanier9 | 0:0c8930416cda | 8 | } |
| glanier9 | 0:0c8930416cda | 9 | // class method to play a note based on PwmOut class |
| glanier9 | 0:0c8930416cda | 10 | void PlayNote(float frequency, float duration, float volume) { |
| glanier9 | 0:0c8930416cda | 11 | _pin.period(1.0/frequency); |
| glanier9 | 0:0c8930416cda | 12 | _pin = volume/2.0; |
| glanier9 | 0:0c8930416cda | 13 | wait(duration); |
| glanier9 | 0:0c8930416cda | 14 | _pin = 0.0; |
| glanier9 | 0:0c8930416cda | 15 | } |
| glanier9 | 0:0c8930416cda | 16 | |
| glanier9 | 0:0c8930416cda | 17 | private: |
| glanier9 | 0:0c8930416cda | 18 | PwmOut _pin; |
| glanier9 | 0:0c8930416cda | 19 | }; |