IoT IR Distance Sensor Robot
Dependencies: Motordriver mbed
Speaker.h@0:dd2edc44362a, 2016-03-16 (annotated)
- Committer:
- suyash95
- Date:
- Wed Mar 16 17:10:55 2016 +0000
- Revision:
- 0:dd2edc44362a
IoT IR Deistance Sensor Robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suyash95 | 0:dd2edc44362a | 1 | #include "mbed.h" |
suyash95 | 0:dd2edc44362a | 2 | // new class to play a note on Speaker based on PwmOut class |
suyash95 | 0:dd2edc44362a | 3 | class Speaker |
suyash95 | 0:dd2edc44362a | 4 | { |
suyash95 | 0:dd2edc44362a | 5 | public: |
suyash95 | 0:dd2edc44362a | 6 | Speaker(PinName pin) : _pin(pin) { |
suyash95 | 0:dd2edc44362a | 7 | // _pin(pin) means pass pin to the Speaker Constructor |
suyash95 | 0:dd2edc44362a | 8 | } |
suyash95 | 0:dd2edc44362a | 9 | // class method to play a note based on PwmOut class |
suyash95 | 0:dd2edc44362a | 10 | void PlayNote(float frequency, float duration, float volume) { |
suyash95 | 0:dd2edc44362a | 11 | _pin.period(1.0/frequency); |
suyash95 | 0:dd2edc44362a | 12 | _pin = volume/2.0; |
suyash95 | 0:dd2edc44362a | 13 | wait(duration); |
suyash95 | 0:dd2edc44362a | 14 | _pin = 0.0; |
suyash95 | 0:dd2edc44362a | 15 | } |
suyash95 | 0:dd2edc44362a | 16 | |
suyash95 | 0:dd2edc44362a | 17 | private: |
suyash95 | 0:dd2edc44362a | 18 | PwmOut _pin; |
suyash95 | 0:dd2edc44362a | 19 | }; |