SharpShooter

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

Committer:
jboettcher
Date:
Thu Oct 27 23:10:15 2016 +0000
Revision:
1:8a3fa9e90572
Parent:
Speaker.h@0:137546fb5da1
misc;

Who changed what in which revision?

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