Part 2 of our ECE 4180 Final Project

Dependencies:   4DGL-uLCD-SE MODSERIAL USBHost wave_player

Committer:
mohit1234
Date:
Fri May 01 18:10:34 2015 +0000
Revision:
0:25c861ee0c38
;

Who changed what in which revision?

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