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.
Fork of beep by
beep.cpp
00001 #include "beep.h" 00002 #include "mbed.h" 00003 00004 /** class to make sound with a buzzer, based on a PwmOut 00005 * The class use a timeout to switch off the sound - it is not blocking while making noise 00006 * 00007 * Example: 00008 * @code 00009 * // Beep with 1Khz for 0.5 seconds 00010 * #include "mbed.h" 00011 * #include "beep.h" 00012 * 00013 * Beep buzzer(p21); 00014 * 00015 * int main() { 00016 * ... 00017 * buzzer.beep(1000,0.5); 00018 * ... 00019 * } 00020 * @endcode 00021 */ 00022 00023 using namespace mbed; 00024 // constructor 00025 /** Create a Beep object connected to the specified PwmOut pin 00026 * 00027 * @param pin PwmOut pin to connect to 00028 */ 00029 00030 Beep::Beep(PinName pin) : _digitalOut(pin) { 00031 _digitalOut.write(0); // after creating it have to be off 00032 } 00033 00034 /** stop the beep instantaneous 00035 * usually not used 00036 */ 00037 void Beep::nobeep() { 00038 _digitalOut.write(0); 00039 } 00040 00041 /** Beep with given frequency and duration. 00042 * 00043 * @param frequency - the frequency of the tone in Hz 00044 * @param time - the duration of the tone in seconds 00045 */ 00046 00047 void Beep::beep(float time) { 00048 00049 _digitalOut.write(1); 00050 toff.attach(this,&Beep::nobeep, time); // time to off 00051 } 00052 00053 00054 00055
Generated on Tue Jul 12 2022 11:22:08 by
1.7.2
