![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
One player pong with seven segment display for score keeping
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of ECE2036Lab2StarterCode by
Speaker.h@0:356124c0bafc, 2014-06-17 (annotated)
- Committer:
- jlind6
- Date:
- Tue Jun 17 20:03:41 2014 +0000
- Revision:
- 0:356124c0bafc
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jlind6 | 0:356124c0bafc | 1 | #include "mbed.h" |
jlind6 | 0:356124c0bafc | 2 | // new class to play a note on Speaker based on PwmOut class |
jlind6 | 0:356124c0bafc | 3 | #ifndef _SPEAKER_H |
jlind6 | 0:356124c0bafc | 4 | #define _SPEAKER_H |
jlind6 | 0:356124c0bafc | 5 | class Speaker |
jlind6 | 0:356124c0bafc | 6 | { |
jlind6 | 0:356124c0bafc | 7 | public: |
jlind6 | 0:356124c0bafc | 8 | Speaker(PinName pin) : _pin(pin) { |
jlind6 | 0:356124c0bafc | 9 | // _pin(pin) means pass pin to the Speaker Constructor |
jlind6 | 0:356124c0bafc | 10 | } |
jlind6 | 0:356124c0bafc | 11 | // class method to play a note based on PwmOut class |
jlind6 | 0:356124c0bafc | 12 | void PlayNote(float frequency, float duration, float volume) { |
jlind6 | 0:356124c0bafc | 13 | _pin.period(1.0/frequency); |
jlind6 | 0:356124c0bafc | 14 | _pin = volume/2.0; |
jlind6 | 0:356124c0bafc | 15 | wait(duration); |
jlind6 | 0:356124c0bafc | 16 | _pin = 0.0; |
jlind6 | 0:356124c0bafc | 17 | } |
jlind6 | 0:356124c0bafc | 18 | |
jlind6 | 0:356124c0bafc | 19 | private: |
jlind6 | 0:356124c0bafc | 20 | PwmOut _pin; |
jlind6 | 0:356124c0bafc | 21 | }; |
jlind6 | 0:356124c0bafc | 22 | |
jlind6 | 0:356124c0bafc | 23 | #endif // _SPEAKER_H |