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: ButtonMusical.cpp
- Revision:
- 8:60231840370f
- Child:
- 10:6e18b220e10c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ButtonMusical.cpp	Sat Sep 19 10:04:37 2015 +0000
@@ -0,0 +1,29 @@
+#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)  { 
+        pressTimes=0;
+    }
+ 
+    void press() {
+        if(pressTimes==0)
+        {
+            sp->changeFrequency(_note.getFrequency());
+            pressTimes++;
+        }
+    }
+ 
+    void release() {        
+        sp->changeFrequency(-_note.getFrequency()*pressTimes);
+        pressTimes=0;
+    }
+    
+
+private:
+    Note _note;
+    int pressTimes;
+    Speaker* sp;
+};
\ No newline at end of file
    