Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed MMA8451Q TSI
Diff: Speaker.h
- Revision:
- 6:459ddd3079fa
- Child:
- 8:60231840370f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h Tue Aug 25 14:12:19 2015 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+// based on zchen311 implementation
+// http://mbed.org/users/zchen311/code/Speaker/
+class Speaker
+{
+public:
+ Speaker(PinName pin) : _pin(pin) {
+ // _pin(pin) means pass pin to the Speaker Constructor
+ frequency=0;
+ _volume=0.2;
+ }
+ // class method to play a note based on PwmOut class
+ void changeFrequency(int delta) {
+ frequency+=delta;
+ if(frequency >0){
+ _pin.period(1.0/frequency);
+ _pin = _volume/2.0;
+ } else {
+ _pin = 0;
+ }
+ }
+ int getFreq(){
+ return frequency;
+ }
+ float* getVolumeBuffer(){
+ return &_volume;
+ }
+private:
+ PwmOut _pin;
+ float _volume;
+ int frequency;
+};
\ No newline at end of file
