Mbed Clock application using an NTP connection to get internet time and a terminal interface to send commands

Dependencies:   4DGL-uLCD-SE EthernetInterface NTPClient mbed-rtos mbed SDFileSystem wavfile

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Speaker.h Source File

Speaker.h

00001 #include "mbed.h"
00002 // new class to play a note on Speaker based on PwmOut class
00003 class Speaker
00004 {
00005 private:
00006 // sets up specified pin for PWM using PwmOut class 
00007     PwmOut pin;
00008     Ticker ticker;
00009     void flipPin() {
00010         pin = 0.0;
00011     }
00012 public:
00013     Speaker(PinName pin) : pin(pin) {
00014 // _pin(pin) means pass pin to the Speaker Constructor
00015     }
00016 // class method to play a note based on PwmOut class
00017     void playNote(float frequency, float duration, float volume) {
00018         pin.period(1.0/frequency);
00019         pin = volume/2.0;
00020         ticker.attach(this, &Speaker::flipPin, duration);
00021         //wait(duration);
00022         //pin = 0.0;
00023     } 
00024 
00025 };
00026