Send a beep to a speaker

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
faif
Date:
Sun Jan 22 19:14:30 2017 +0000
Commit message:
Beep a speaker

Changed in this revision

beep.cpp Show annotated file Show diff for this revision Revisions of this file
beep.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c2090cf6119d beep.cpp
--- /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
diff -r 000000000000 -r c2090cf6119d beep.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.h	Sun Jan 22 19:14:30 2017 +0000
@@ -0,0 +1,9 @@
+#ifndef BEEP_H
+#define BEEP_H
+
+DigitalOut speaker(p20);
+DigitalIn button(p18);
+
+void play_sound(DigitalOut& out, float delay);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r c2090cf6119d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jan 22 19:14:30 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file