Gregory Boudreau / Mbed 2 deprecated Lab6_2036_turkey_greg

Dependencies:   4DGL-uLCD-SE PinDetect mbed

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 
00004 #include "mbed.h"
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     
00013     // class method to play a note based on PwmOut class
00014     void PlayNote(float frequency, float duration, float volume) {
00015         _pin.period(1.0/frequency);
00016         _pin = volume/2.0;
00017         wait(duration);
00018         _pin = 0.0;
00019     }
00020 
00021 private:
00022     PwmOut _pin;
00023 };
00024 
00025 #endif