Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
Diff: UI/Beep/Beep.h
- Revision:
- 0:826c6171fc1b
diff -r 000000000000 -r 826c6171fc1b UI/Beep/Beep.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/Beep/Beep.h Wed Jun 20 14:57:48 2012 +0000 @@ -0,0 +1,49 @@ +#ifndef MBED_BEEP_H +#define MBED_BEEP_H + +#include "mbed.h" + +/** Generates a tone with a buzzer, based on a PwmOut + * The class use a timeout to switch off the sound - it is not blocking while making noise + * + * Example: + * @code + * // Beep at 2kHz for 0.5 seconds + * #include "mbed.h" + * #include "Beep.h" + * + * Beep buzzer(p21); + * + * int main() { + * ... + * buzzer.beep(2000,0.5); + * ... + * } + * @endcode + */ +class Beep { + +public: + +/** Create a Beep object connected to the specified PwmOut pin + * + * @param pin PwmOut pin to connect to + */ + Beep(PinName pin); + +/** Beep with given frequency and duration. + * + * @param frequency - the frequency of the tone in Hz + * @param time - the duration of the tone in seconds + */ + void beep(float frequency, float time); + +/** stop the beep instantaneously. Not typically needed, but here just in case + */ + void nobeep(); + +private : + PwmOut _pwm; + Timeout toff; +}; +#endif