This is a remake of tetris game for mbed. Please see detail here http://developer.mbed.org/users/sucrelv/notebook/tetris-game-on-mbed
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Speaker.h@0:3b5e97ab5884, 2014-10-21 (annotated)
- Committer:
- sucrelv
- Date:
- Tue Oct 21 15:10:36 2014 +0000
- Revision:
- 0:3b5e97ab5884
initial upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sucrelv | 0:3b5e97ab5884 | 1 | #include "mbed.h" |
sucrelv | 0:3b5e97ab5884 | 2 | // new class to play a note on Speaker based on PwmOut class |
sucrelv | 0:3b5e97ab5884 | 3 | class Speaker |
sucrelv | 0:3b5e97ab5884 | 4 | { |
sucrelv | 0:3b5e97ab5884 | 5 | public: |
sucrelv | 0:3b5e97ab5884 | 6 | Speaker(PinName pin) : _pin(pin) { |
sucrelv | 0:3b5e97ab5884 | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
sucrelv | 0:3b5e97ab5884 | 8 | } |
sucrelv | 0:3b5e97ab5884 | 9 | // class method to play a note based on PwmOut class |
sucrelv | 0:3b5e97ab5884 | 10 | void PlayNote(float frequency, float duration, float volume) { |
sucrelv | 0:3b5e97ab5884 | 11 | _pin.period(1.0/frequency); |
sucrelv | 0:3b5e97ab5884 | 12 | _pin = volume/2.0; |
sucrelv | 0:3b5e97ab5884 | 13 | wait(duration); |
sucrelv | 0:3b5e97ab5884 | 14 | _pin = 0.0; |
sucrelv | 0:3b5e97ab5884 | 15 | } |
sucrelv | 0:3b5e97ab5884 | 16 | |
sucrelv | 0:3b5e97ab5884 | 17 | private: |
sucrelv | 0:3b5e97ab5884 | 18 | PwmOut _pin; |
sucrelv | 0:3b5e97ab5884 | 19 | }; |