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 wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem FATFileSystem
Speaker.h@0:567492543056, 2019-04-12 (annotated)
- Committer:
- rhuang77
- Date:
- Fri Apr 12 01:18:47 2019 +0000
- Revision:
- 0:567492543056
new electric piano code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rhuang77 | 0:567492543056 | 1 | #include "mbed.h" |
| rhuang77 | 0:567492543056 | 2 | // new class to play a note on Speaker based on PwmOut class |
| rhuang77 | 0:567492543056 | 3 | class Speaker |
| rhuang77 | 0:567492543056 | 4 | { |
| rhuang77 | 0:567492543056 | 5 | public: |
| rhuang77 | 0:567492543056 | 6 | Speaker(PinName pin) : _pin(pin) { |
| rhuang77 | 0:567492543056 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
| rhuang77 | 0:567492543056 | 8 | } |
| rhuang77 | 0:567492543056 | 9 | // class method to play a note based on PwmOut class |
| rhuang77 | 0:567492543056 | 10 | void PlayNote(float frequency, float duration, float volume) { |
| rhuang77 | 0:567492543056 | 11 | _pin.period(1.0/frequency); |
| rhuang77 | 0:567492543056 | 12 | _pin = volume/2.0; |
| rhuang77 | 0:567492543056 | 13 | wait(duration); |
| rhuang77 | 0:567492543056 | 14 | _pin = 0.0; |
| rhuang77 | 0:567492543056 | 15 | } |
| rhuang77 | 0:567492543056 | 16 | |
| rhuang77 | 0:567492543056 | 17 | private: |
| rhuang77 | 0:567492543056 | 18 | PwmOut _pin; |
| rhuang77 | 0:567492543056 | 19 | }; |