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
ButtonMusical.cpp
- Committer:
- mfurlanetto
- Date:
- 2015-10-16
- Branch:
- mono
- Revision:
- 10:6e18b220e10c
- Parent:
- 8:60231840370f
File content as of revision 10:6e18b220e10c:
#include "Speaker.h"
#include "Note.cpp"
#include "Button.cpp"
class ButtonMusical: public Button
{
public:
ButtonMusical(PinName pin, Note note, Speaker* speaker) : Button(pin), _note(note), sp(speaker) {
alreadyPressed=false;
}
void press() {
if(!alreadyPressed) {
sp->changeFrequency(_note.getFrequency());
buttonsPressed++;
alreadyPressed=true;
}
}
void release() {
if(alreadyPressed) {
if(--buttonsPressed==0)
sp->stop();
alreadyPressed=false;
}
}
private:
Note _note;
bool alreadyPressed;
Speaker* sp;
int static buttonsPressed;
};
