
Simon: A Memory Game
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Speaker.h@2:c92f0e749b94, 2014-10-21 (annotated)
- Committer:
- cmathis
- Date:
- Tue Oct 21 15:29:16 2014 +0000
- Revision:
- 2:c92f0e749b94
- Parent:
- 0:64ea583d77e2
revision3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cmathis | 0:64ea583d77e2 | 1 | #include "mbed.h" |
cmathis | 0:64ea583d77e2 | 2 | |
cmathis | 0:64ea583d77e2 | 3 | class Speaker |
cmathis | 0:64ea583d77e2 | 4 | { |
cmathis | 0:64ea583d77e2 | 5 | public: |
cmathis | 0:64ea583d77e2 | 6 | Speaker(PinName pin) : _pin(pin) { |
cmathis | 0:64ea583d77e2 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
cmathis | 0:64ea583d77e2 | 8 | } |
cmathis | 0:64ea583d77e2 | 9 | // class method to play a note based on PwmOut class |
cmathis | 0:64ea583d77e2 | 10 | void PlayNote(float frequency, float duration, float volume) { |
cmathis | 0:64ea583d77e2 | 11 | _pin.period(1.0/frequency); |
cmathis | 0:64ea583d77e2 | 12 | _pin = volume/2.0; |
cmathis | 0:64ea583d77e2 | 13 | wait(duration); |
cmathis | 0:64ea583d77e2 | 14 | _pin = 0.0; |
cmathis | 0:64ea583d77e2 | 15 | } |
cmathis | 0:64ea583d77e2 | 16 | |
cmathis | 0:64ea583d77e2 | 17 | private: |
cmathis | 0:64ea583d77e2 | 18 | // sets up specified pin for PWM using PwmOut class |
cmathis | 0:64ea583d77e2 | 19 | PwmOut _pin; |
cmathis | 0:64ea583d77e2 | 20 | }; |