Dependencies:   mbed wave_player

Committer:
Alexw2011
Date:
Mon Mar 14 04:12:35 2016 +0000
Revision:
0:cbaaf2c707d2
Demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alexw2011 0:cbaaf2c707d2 1 #include "mbed.h"
Alexw2011 0:cbaaf2c707d2 2 // new class to play a note on Speaker based on PwmOut class
Alexw2011 0:cbaaf2c707d2 3 class Speaker
Alexw2011 0:cbaaf2c707d2 4 {
Alexw2011 0:cbaaf2c707d2 5 public:
Alexw2011 0:cbaaf2c707d2 6 Speaker(PinName pin) : _pin(pin) {
Alexw2011 0:cbaaf2c707d2 7 // _pin(pin) means pass pin to the Speaker Constructor
Alexw2011 0:cbaaf2c707d2 8 }
Alexw2011 0:cbaaf2c707d2 9 // class method to play a note based on PwmOut class
Alexw2011 0:cbaaf2c707d2 10 void PlayNote(float frequency, float duration, float volume) {
Alexw2011 0:cbaaf2c707d2 11 _pin.period(1.0/frequency);
Alexw2011 0:cbaaf2c707d2 12 _pin = volume/2.0;
Alexw2011 0:cbaaf2c707d2 13 wait(duration);
Alexw2011 0:cbaaf2c707d2 14 _pin = 0.0;
Alexw2011 0:cbaaf2c707d2 15 }
Alexw2011 0:cbaaf2c707d2 16
Alexw2011 0:cbaaf2c707d2 17 private:
Alexw2011 0:cbaaf2c707d2 18 PwmOut _pin;
Alexw2011 0:cbaaf2c707d2 19 };