Create a beeping alarm that starts and stops when you want it to. Created for OspreyQuad project and intended for use with a piezo buzzer.
alarm.cpp
- Committer:
- smnanthny
- Date:
- 2014-01-19
- Revision:
- 0:60cd02d169ea
File content as of revision 0:60cd02d169ea:
#include "mbed.h" #include "alarm.h" using namespace mbed; Alarm :: Alarm(PinName pin) : _pwm(pin) { _pwm.period(1.0/1000); _pwm.write(0.0); active = false; } void Alarm :: startBeep(void) { active = true; beepOn(); } void Alarm :: stopBeep(void) { active = false; } void Alarm :: beepOn(void) { _pwm.write(0.5); beepTimer.attach(this, &Alarm::beepOff, 0.1); } void Alarm :: beepOff(void) { _pwm.write(0.0); if(active) beepTimer.attach(this,&Alarm::beepOn, 0.05); }