![](/media/cache/profiles/3ce0a6bd2fcb665bd7c80284c6cc3a4e.jpg.50x50_q85.jpg)
2016 catch robo
Dependencies: mbed WiiClassicController_kai
Diff: lancer_speaker/lancer_speaker.cpp
- Revision:
- 0:7d81654c5ce8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lancer_speaker/lancer_speaker.cpp Mon Jun 24 07:51:58 2019 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" +#include "lancer_speaker.h" + + +Speaker::Speaker(PinName pin): _pin(pin){ + _pin = 0; +} + +void Speaker::tone(int freq, int duration) +{ + _duration = duration; + _freq = freq; + _time.attach_us(this, &Speaker::flip, 500000/_freq); +} + +void Speaker::noTone() +{ + _time.detach(); +} + +void Speaker::flip() +{ + _pin = !_pin; + if(_duration < _count*500/_freq){ + _count = 0; + _time.detach(); + } + _count++; +} \ No newline at end of file