Li Ruofan 201199450
Dependencies: mbed Gamepad Joystick
Diff: bgm/bgm.cpp
- Revision:
- 8:b4a2954dd74f
- Parent:
- 6:cbd9e1f26a10
diff -r e3844250b77d -r b4a2954dd74f bgm/bgm.cpp --- a/bgm/bgm.cpp Fri May 15 22:23:22 2020 +0000 +++ b/bgm/bgm.cpp Sat May 16 17:26:10 2020 +0000 @@ -1,27 +1,27 @@ #include "bgm.h" // construct & destruct/ -bgm::bgm() +Bgm::Bgm() : _timeout(new Timeout()), _buzzer(new PwmOut(PTC10)) {} -bgm::~bgm() +Bgm::~Bgm() { } -void Sound::tone(float frequency, float duration) +void Bgm::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 ); + _timeout->attach(callback(this, &Bgm::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 -void bgm::welcome(){ +void Bgm::welcome(){ tone(784.0f,0.4f); wait(0.4f); tone(784.0f,0.1f); @@ -61,7 +61,7 @@ } -void bgm::battlefield(){ +void Bgm::battlefield(){ tone(659.0f,0.3f); wait(0.3f); tone(659.0f,0.2f); @@ -107,7 +107,7 @@ } -void bgm::died(){ +void Bgm::died(){ tone(784.0f,0.2f); wait(0.2f); tone(880.0f,0.3f); @@ -135,7 +135,7 @@ } -void bgm::tone_off() +void Bgm::tone_off() { // called after timeout _buzzer->write(0.0);