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.c
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) : _pwm(pin) { 00031 _pwm.write(0.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 _pwm.write(0.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::beepFreq(float freq){ 00048 00049 _pwm.period(1.0/freq); 00050 } 00051 void Beep::beepTime(float time) { 00052 _pwm.write(0.5); // 50% duty cycle - beep on 00053 toff.attach(this,&Beep::nobeep, time); // time to off 00054 } 00055 00056 00057 00058
Generated on Mon Jul 18 2022 08:17:52 by
1.7.2
