TVZ2022 / Pavetic_BuzzerLib
Revision:
0:f867aece57de
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Buzzer.cpp	Sun Nov 27 10:33:00 2022 +0000
@@ -0,0 +1,21 @@
+#include "Buzzer.h"
+
+using namespace mbed;
+
+Buzzer::Buzzer(PinName pin) : _pwm(pin) { _pwm.write(0.0); }
+
+void Buzzer::silence() { _pwm.write(0.0); }
+void empty() {
+}
+
+/**
+ * Buzzer with given frequency and rithm.
+ *
+ * @param frequency - the frequency of the tone in Hz
+ * @param rithm - rithm of the song
+ */
+void Buzzer::buzz(float freq, float rithm) {
+  _pwm.period(1.0 / freq);
+  _pwm.write(0.5f);
+    ThisThread::sleep_for(Kernel::Clock::duration_u32((int)(rithm * 500)));
+}