uLCD robot moveable via pushbuttons

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Committer:
jboettcher
Date:
Sun Nov 06 21:57:20 2016 +0000
Revision:
0:327ccd5eafc8
Complete

Who changed what in which revision?

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