Flappy Bird game on mbed with a micro LCD screen, class D amp, speaker, SD card reader/writer, 5-button navigation switch, and potentiometer speed control
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed
Speaker.h@0:cd1d2540aaf4, 2016-03-15 (annotated)
- Committer:
- Mpmart08
- Date:
- Tue Mar 15 01:11:07 2016 +0000
- Revision:
- 0:cd1d2540aaf4
added comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mpmart08 | 0:cd1d2540aaf4 | 1 | #include "mbed.h" |
Mpmart08 | 0:cd1d2540aaf4 | 2 | |
Mpmart08 | 0:cd1d2540aaf4 | 3 | // class to play a note on Speaker based on PwmOut class |
Mpmart08 | 0:cd1d2540aaf4 | 4 | #ifndef _SPEAKER_H |
Mpmart08 | 0:cd1d2540aaf4 | 5 | #define _SPEAKER_H |
Mpmart08 | 0:cd1d2540aaf4 | 6 | |
Mpmart08 | 0:cd1d2540aaf4 | 7 | class Speaker |
Mpmart08 | 0:cd1d2540aaf4 | 8 | { |
Mpmart08 | 0:cd1d2540aaf4 | 9 | public: |
Mpmart08 | 0:cd1d2540aaf4 | 10 | // Constructor |
Mpmart08 | 0:cd1d2540aaf4 | 11 | Speaker(PinName pin) : _pin(pin) {} |
Mpmart08 | 0:cd1d2540aaf4 | 12 | // member function to play a given note |
Mpmart08 | 0:cd1d2540aaf4 | 13 | void PlayNote(float frequency, float duration, float volume) { |
Mpmart08 | 0:cd1d2540aaf4 | 14 | _pin.period(1.0/frequency); |
Mpmart08 | 0:cd1d2540aaf4 | 15 | _pin = volume/2.0; |
Mpmart08 | 0:cd1d2540aaf4 | 16 | wait(duration); |
Mpmart08 | 0:cd1d2540aaf4 | 17 | _pin = 0.0; |
Mpmart08 | 0:cd1d2540aaf4 | 18 | } |
Mpmart08 | 0:cd1d2540aaf4 | 19 | |
Mpmart08 | 0:cd1d2540aaf4 | 20 | private: |
Mpmart08 | 0:cd1d2540aaf4 | 21 | PwmOut _pin; |
Mpmart08 | 0:cd1d2540aaf4 | 22 | }; |
Mpmart08 | 0:cd1d2540aaf4 | 23 | |
Mpmart08 | 0:cd1d2540aaf4 | 24 | #endif // _SPEAKER_H |