Li Ruofan 201199450

Dependencies:   mbed Gamepad Joystick

Revision:
6:cbd9e1f26a10
Parent:
3:cf9fead9c3f4
Child:
8:b4a2954dd74f
--- a/bgm/bgm.cpp	Fri May 15 19:57:40 2020 +0000
+++ b/bgm/bgm.cpp	Fri May 15 21:16:14 2020 +0000
@@ -2,12 +2,22 @@
 
 // construct & destruct/
 bgm::bgm()
-{
-}
+    :
+    _timeout(new Timeout()),
+    _buzzer(new PwmOut(PTC10))
+{}
+
 bgm::~bgm()
 {
+    
 }
 
+void Sound::tone(float frequency, float duration)
+{
+    _buzzer->period(1.0f/frequency);
+    _buzzer->write(0.5);  // 50% duty cycle - square wave
+    _timeout->attach(callback(this, &Sound::tone_off), duration );
+}
 // The number "1,2,3,4,5,6,7" means each number note in the notation
 
 // Excerpted from famous Chinese and English songs