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
- Branch:
- mono
- Revision:
- 10:6e18b220e10c
- Parent:
- 8:60231840370f
--- a/Speaker.h Wed Sep 23 15:38:04 2015 +0000
+++ b/Speaker.h Fri Oct 16 16:38:29 2015 +0000
@@ -9,31 +9,25 @@
{
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(double delta) {
- frequency+=delta;
- if(frequency >0){
- _pin.period(1.0/frequency);
+ void changeFrequency(double newNote) {
+ _pin.period(1.0/newNote);
_pin = _volume/2.0;
- } else {
- _pin = 0;
- frequency=0;
- }
}
- double getFreq(){
- return frequency;
+
+ void stop(){
+ _pin=1;
+ _pin.period(0);
}
+
float* getVolumeBuffer(){
return &_volume;
}
private:
PwmOut _pin;
float _volume;
- double frequency;
};
#endif
\ No newline at end of file
