/

Dependents:   Semafor-Jukicic

Revision:
0:f563386d7c59
diff -r 000000000000 -r f563386d7c59 buzzer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buzzer.cpp	Sun Feb 21 17:26:30 2021 +0000
@@ -0,0 +1,27 @@
+#include "buzzer.h"
+#include "mbed.h"
+ 
+using namespace mbed;
+ 
+Beep::Beep(PinName pin) : _pwm(pin)
+{
+    _pwm.write(0.0);
+}
+ 
+void Beep::nobeep()
+{
+    _pwm.write(0.0);
+}
+ 
+/** Beep with given frequency and duration.
+ *
+ * @param frequency - the frequency of the tone in Hz
+ * @param time - the duration of the tone in seconds
+ */
+void Beep::beep(float freq, float time)
+{
+ 
+    _pwm.period(1.0/freq);
+    _pwm.write(0.5);
+    toff.attach(this,&Beep::nobeep, time);
+}
\ No newline at end of file