Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ParkingSENSOR ParkingSENSOR AwesomeAlarm_BLE DrivingLayerV0004 ... more
buzzer.h
00001 #ifndef MBED_BEEP_H 00002 #define MBED_BEEP_H 00003 00004 #include "mbed.h" 00005 /** 00006 @namespace Beep Library 00007 @brief Contains member functions for the speaker funtion that allow for sending of frequency of sounds and duration through pwm 00008 @Author Peter Drescher (I do not own the rights to this library and it has been rightly attributed to its owner 00009 @Revision 2012 00010 00011 **/ 00012 00013 00014 00015 /** class to make sound with a buzzer, roughly based on a library created by Peter Drescher 00016 * The class use a timeout to switch off the sound - it is not blocking while making noise 00017 * 00018 * Example: 00019 * @code 00020 * // Beep with 1Khz for 0.5 seconds 00021 * #include "mbed.h" 00022 * #include "buzzer.h" 00023 * 00024 * Beep buzzer(PTC2); 00025 * 00026 * int main() { 00027 * ... 00028 * buzzer.beep(1000,0.5); 00029 * ... 00030 * } 00031 * @endcode 00032 */ 00033 00034 00035 namespace mbed { 00036 00037 /* Class: Beep 00038 * A class witch uses pwm to controle a beeper to generate sounds. 00039 */ 00040 class Beep { 00041 00042 public: 00043 00044 /** Create a Beep object connected to the specified PwmOut pin 00045 * 00046 * @param pin PwmOut pin to connect to 00047 */ 00048 Beep (PinName pin); 00049 00050 /** Beep with given frequency and duration. 00051 * 00052 * @param frequency - the frequency of the tone in Hz 00053 * @param time - the duration of the tone in seconds 00054 */ 00055 void beep (float frequency, float time); 00056 00057 /** stop the beep instantaneous 00058 * usually not used 00059 */ 00060 void nobeep(); 00061 00062 private : 00063 PwmOut _pwm; 00064 Timeout toff; 00065 }; 00066 00067 } 00068 #endif 00069 00070
Generated on Tue Jul 12 2022 16:39:30 by
1.7.2