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:
- 8:60231840370f
- Parent:
- 6:459ddd3079fa
- Child:
- 10:6e18b220e10c
--- a/Speaker.h Fri Sep 18 15:46:20 2015 +0000
+++ b/Speaker.h Sat Sep 19 10:04:37 2015 +0000
@@ -1,4 +1,7 @@
#include "mbed.h"
+
+#ifndef SPEAKER
+#define SPEAKER
// new class to play a note on Speaker based on PwmOut class
// based on zchen311 implementation
// http://mbed.org/users/zchen311/code/Speaker/
@@ -11,16 +14,17 @@
_volume=0.2;
}
// class method to play a note based on PwmOut class
- void changeFrequency(int delta) {
+ void changeFrequency(double delta) {
frequency+=delta;
if(frequency >0){
_pin.period(1.0/frequency);
_pin = _volume/2.0;
} else {
_pin = 0;
+ frequency=0;
}
}
- int getFreq(){
+ double getFreq(){
return frequency;
}
float* getVolumeBuffer(){
@@ -29,5 +33,7 @@
private:
PwmOut _pin;
float _volume;
- int frequency;
-};
\ No newline at end of file
+ double frequency;
+};
+
+#endif
\ No newline at end of file
