Chris Taylor / Mbed 2 deprecated RETRO-CityRally

Dependencies:   mbed

Revision:
1:1b8125937f28
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Beeper.cpp	Sun Feb 01 00:43:25 2015 +0000
@@ -0,0 +1,27 @@
+#include "Beeper.h"
+
+DigitalOut Beeper::_speaker(P0_18);
+
+void Beeper::beep(int freq, int ms)
+{
+    float delay = 1.0f / (float)freq;
+    float duration = (float)ms / 1000.0f;
+    while (duration > 0)
+    {
+        _speaker = !_speaker;        
+        wait(delay);
+        duration -= delay;
+    }
+}
+
+void Beeper::noise(int freq, int ms)
+{
+    float delay = 1.0f / (float)freq;
+    float duration = (float)ms / 1000.0f;
+    while (duration > 0)
+    {
+        _speaker = lfsr_rand() & 0x01;
+        wait(delay);
+        duration -= delay;
+    }
+}
\ No newline at end of file