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
Speaker.h
- Committer:
- mfurlanetto
- Date:
- 2015-08-25
- Revision:
- 6:459ddd3079fa
- Child:
- 8:60231840370f
File content as of revision 6:459ddd3079fa:
#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;
};
