zzzz

Revision:
0:6d2a1fb93e9e
Child:
1:931e45afbcb4
diff -r 000000000000 -r 6d2a1fb93e9e Audio.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Audio.cpp	Fri Jul 05 10:33:07 2019 +0000
@@ -0,0 +1,38 @@
+#include "Audio.h"
+
+double nada[9] = {247, 262, 294, 330, 350, 392, 440, 494, 523};
+
+Audio::Audio(PinName buzzer): out(buzzer)
+{
+}
+    
+void Audio::SetVolume(double volume)
+{
+    vol = volume;
+}   
+
+void Audio::SetDuration(unsigned int milisec)
+{
+    ms = milisec;
+}
+        
+void Audio::PlayNote(unsigned int angka)
+{
+    if(angka > 8) angka = 8;
+    
+    double Nada = nada[angka];
+    PlayNote(Nada*4.24, ms, vol);
+}
+
+void Audio::mute()
+{
+    out = 0;
+}
+
+void Audio::PlayNote(double frequency, double duration, double volume)
+{
+    out.period(1.0/frequency);
+    out = volume/2.0;
+    wait_ms(duration);
+    out = 0.0;
+}