Make noise with a piezo buzzer. Use a pwm pin.
Fork of beep by
Embed:
(wiki syntax)
Show/hide line numbers
beep.h
00001 #ifndef MBED_BEEP_H 00002 #define MBED_BEEP_H 00003 00004 #include "mbed.h" 00005 00006 /** class to make sound 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 with 1Khz 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(1000,0.5); 00020 * ... 00021 * } 00022 * @endcode 00023 */ 00024 00025 00026 namespace mbed { 00027 00028 /* Class: Beep 00029 * A class witch uses pwm to controle a beeper to generate sounds. 00030 */ 00031 class Beep { 00032 00033 public: 00034 00035 /** Create a Beep object connected to the specified PwmOut pin 00036 * 00037 * @param pin PwmOut pin to connect to 00038 */ 00039 Beep (PinName pin); 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 void beep (float frequency, float time); 00047 00048 /** stop the beep instantaneous 00049 * usually not used 00050 */ 00051 void nobeep(); 00052 00053 private : 00054 PwmOut _pwm; 00055 Timeout toff; 00056 }; 00057 00058 } 00059 #endif
Generated on Sun Jul 17 2022 05:13:32 by 1.7.2