Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Beep.h Source File

Beep.h

00001 #ifndef MBED_BEEP_H
00002 #define MBED_BEEP_H
00003 
00004 #include "mbed.h"
00005 
00006 /** Generates a tone with a buzzer, based on a PwmOut
00007  * The class use a timeout to switch off the sound  - it is not blocking while making noise
00008  *
00009  * Example:
00010  * @code
00011  * // Beep at 2kHz for 0.5 seconds
00012  * #include "mbed.h"
00013  * #include "Beep.h"
00014  * 
00015  * Beep buzzer(p21);
00016  * 
00017  * int main() {
00018  *        ...
00019  *   buzzer.beep(2000,0.5);    
00020  *       ...
00021  * }
00022  * @endcode
00023  */
00024 class Beep {
00025 
00026 public:
00027 
00028 /** Create a Beep object connected to the specified PwmOut pin
00029  *
00030  * @param pin PwmOut pin to connect to 
00031  */
00032     Beep(PinName pin);
00033 
00034 /** Beep with given frequency and duration.
00035  *
00036  * @param frequency - the frequency of the tone in Hz
00037  * @param time - the duration of the tone in seconds
00038  */
00039     void beep(float frequency, float time);
00040 
00041 /** stop the beep instantaneously. Not typically needed, but here just in case
00042  */
00043     void nobeep();
00044 
00045 private :
00046     PwmOut _pwm;
00047     Timeout toff;
00048 };
00049 #endif