ECE_4180_Project / Mbed 2 deprecated Final_Project_ECE_4180

Dependencies:   4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Speaker.h Source File

Speaker.h

00001 #ifndef SPEAKER_H
00002 #define SPEAKER_H
00003 #include "mbed.h"
00004 
00005 // new class to play a note on Speaker based on PwmOut class
00006 class Speaker
00007 {
00008 public:
00009     Speaker(PinName pin) : _pin(pin) {
00010 // _pin(pin) means pass pin to the Speaker Constructor
00011     }
00012 // class method to play a note based on PwmOut class
00013     void PlayNote(float frequency, float duration, float volume) {
00014         _pin.period(1.0/frequency);
00015         _pin = volume/2.0;
00016         wait(duration);
00017         _pin = 0.0;
00018     }
00019 
00020 private:
00021     PwmOut _pin;
00022 };
00023 #endif