Lab 2 for ECE 2036 (work in progress)

Dependencies:   mbed 4DGL-uLCD-SE SDFileSystem PinDetect

Committer:
jmcmath
Date:
Mon Feb 11 04:31:13 2019 +0000
Revision:
0:f10415100c39
work in progress

Who changed what in which revision?

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