First Draft, serial print change based on distance

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 /** Beep Class
00007  *  @brief Acknowledgements to EJ Teb
00008  *
00009  *  @brief class to make sound with a buzzer, based on a PwmOut
00010  *  @brief The class use a timeout to switch off the sound  - it is not blocking while making noise
00011  *
00012  * Example:
00013  * @code
00014  * // Beep with 1Khz for 0.5 seconds
00015  * #include "mbed.h"
00016  * #include "beep.h"
00017  * 
00018  * Beep buzzer(p21);
00019  * 
00020  * int main() {
00021  *        ...
00022  *   buzzer.beep(1000,0.5);    
00023  *       ...
00024  * }
00025  * @endcode
00026  */
00027 
00028 
00029 namespace mbed {
00030 
00031 /* Class: Beep
00032  *  A class witch uses pwm to controle a beeper to generate sounds.
00033  */
00034 class Beep {
00035 
00036 public:
00037 
00038 /** Create a Beep object connected to the specified PwmOut pin
00039  *
00040  * @param pin PwmOut pin to connect to 
00041  */
00042     Beep (PinName PTC10);
00043 
00044 /** Beep with given frequency and duration.
00045  *
00046  * @param frequency - the frequency of the tone in Hz
00047  * @param time - the duration of the tone in seconds
00048  */
00049     void beep (float frequency, float time);
00050 
00051 /** stop the beep instantaneous 
00052  * usually not used 
00053  */
00054     void nobeep();
00055 
00056 private :
00057     PwmOut _pwm;
00058     Timeout toff;
00059 };
00060 
00061 }
00062 #endif