![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple starter skeleton for asteroids video game.
Speaker.h@0:0c450cb95a1e, 2019-02-21 (annotated)
- Committer:
- jhurley31
- Date:
- Thu Feb 21 17:44:23 2019 +0000
- Revision:
- 0:0c450cb95a1e
Starting the buzzman project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhurley31 | 0:0c450cb95a1e | 1 | #include "mbed.h" |
jhurley31 | 0:0c450cb95a1e | 2 | // new class to play a note on Speaker based on PwmOut class |
jhurley31 | 0:0c450cb95a1e | 3 | class Speaker |
jhurley31 | 0:0c450cb95a1e | 4 | { |
jhurley31 | 0:0c450cb95a1e | 5 | public: |
jhurley31 | 0:0c450cb95a1e | 6 | Speaker(PinName pin) : _pin(pin) { |
jhurley31 | 0:0c450cb95a1e | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
jhurley31 | 0:0c450cb95a1e | 8 | } |
jhurley31 | 0:0c450cb95a1e | 9 | // class method to play a note based on PwmOut class |
jhurley31 | 0:0c450cb95a1e | 10 | void PlayNote(float frequency, float duration, float volume) { |
jhurley31 | 0:0c450cb95a1e | 11 | _pin.period(1.0/frequency); |
jhurley31 | 0:0c450cb95a1e | 12 | _pin = volume/2.0; |
jhurley31 | 0:0c450cb95a1e | 13 | wait(duration); |
jhurley31 | 0:0c450cb95a1e | 14 | _pin = 0.0; |
jhurley31 | 0:0c450cb95a1e | 15 | } |
jhurley31 | 0:0c450cb95a1e | 16 | |
jhurley31 | 0:0c450cb95a1e | 17 | private: |
jhurley31 | 0:0c450cb95a1e | 18 | PwmOut _pin; |
jhurley31 | 0:0c450cb95a1e | 19 | }; |
jhurley31 | 0:0c450cb95a1e | 20 |