A simple asteroids-like game utilizing various Mbed-compatible sensors
Dependencies: mbed 4DGL-uLCD-SE PinDetect
Speaker.h@0:f2cc64948895, 2018-11-30 (annotated)
- Committer:
- sralph3
- Date:
- Fri Nov 30 04:49:11 2018 +0000
- Revision:
- 0:f2cc64948895
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sralph3 | 0:f2cc64948895 | 1 | #include "mbed.h" |
sralph3 | 0:f2cc64948895 | 2 | // new class to play a note on Speaker based on PwmOut class |
sralph3 | 0:f2cc64948895 | 3 | class Speaker |
sralph3 | 0:f2cc64948895 | 4 | { |
sralph3 | 0:f2cc64948895 | 5 | public: |
sralph3 | 0:f2cc64948895 | 6 | Speaker(PinName pin) : _pin(pin) { |
sralph3 | 0:f2cc64948895 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
sralph3 | 0:f2cc64948895 | 8 | } |
sralph3 | 0:f2cc64948895 | 9 | // class method to play a note based on PwmOut class |
sralph3 | 0:f2cc64948895 | 10 | void PlayNote(float frequency, float duration, float volume) { |
sralph3 | 0:f2cc64948895 | 11 | _pin.period(1.0/frequency); |
sralph3 | 0:f2cc64948895 | 12 | _pin = volume/2.0; |
sralph3 | 0:f2cc64948895 | 13 | wait(duration); |
sralph3 | 0:f2cc64948895 | 14 | _pin = 0.0; |
sralph3 | 0:f2cc64948895 | 15 | } |
sralph3 | 0:f2cc64948895 | 16 | |
sralph3 | 0:f2cc64948895 | 17 | private: |
sralph3 | 0:f2cc64948895 | 18 | PwmOut _pin; |
sralph3 | 0:f2cc64948895 | 19 | }; |