Lab 3 Part 4

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem

Committer:
glanier9
Date:
Thu Feb 25 18:30:28 2021 +0000
Revision:
12:94b16c66c09a
Version 1. Logic for Bluetooth not working.

Who changed what in which revision?

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