Toggle the LED of the LPC1768 using an electret microphone

Dependencies:   mbed

Revision:
0:01301c8c38ab
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sound_switch.cpp	Sun Jun 04 11:50:37 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "sound_switch.h"
+
+static const float THRESHOLD = 0.5;
+const float BOUNCE_DELAY = 0.2;
+
+enum 
+{
+    OFF = 0,
+    ON = 1
+};
+
+int main() 
+{
+    float i;
+    while (true)
+    {        
+        i = mic;
+        if (i < THRESHOLD)
+        {
+            toggle_state(myled);
+            wait(BOUNCE_DELAY);
+        }
+    }
+}
+
+void toggle_state(DigitalOut& s)
+{
+    switch(s)
+    {
+        case OFF:
+            s = ON;
+            break;
+        case ON:
+            s = OFF;
+            break;
+    }
+}
\ No newline at end of file