Send a beep to a speaker

Dependencies:   mbed

Revision:
0:c2090cf6119d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.cpp	Sun Jan 22 19:14:30 2017 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+#include "beep.h"
+
+static const float delay = 1E-3; // 0.001
+
+int main() 
+{
+    while (true)
+    {
+        if (button)
+        {
+            play_sound(speaker, delay);
+        }
+    }
+}
+
+
+void play_sound(DigitalOut& speaker, float delay)
+{
+    speaker = 1;
+    wait(delay);
+    speaker = 0;
+    wait(delay);
+}
\ No newline at end of file