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-10-26
- Branch:
- mono
- Revision:
- 17:01fe47dda43b
- Parent:
- 10:6e18b220e10c
File content as of revision 17:01fe47dda43b:
#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/
class Speaker
{
public:
Speaker(PinName pin) : _pin(pin) {
_volume=0.2;
}
// class method to play a note based on PwmOut class
void changeFrequency(double newNote) {
_pin.period(1.0/newNote);
_pin = _volume/2.0;
}
void stop(){
_pin=1;
_pin.period(0);
}
float* getVolumeBuffer(){
return &_volume;
}
private:
PwmOut _pin;
float _volume;
};
#endif
