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.
Dependencies: mbed
piezo_bz.h
00001 /* 00002 * Mbed library program 00003 * Control Piezo Transducer 00004 * 00005 * Copyright (c) 2018 Kenji Arai / JH1PJL 00006 * http://www.page.sannet.ne.jp/kenjia/index.html 00007 * http://mbed.org/users/kenjiArai/ 00008 * Created: Feburary 28th, 2018 00009 * Revised: March 3rd, 2018 00010 */ 00011 00012 // Tested: Nucleo-F446RE with Akizuki PT08-Z185R 00013 // http://akizukidenshi.com/catalog/g/gP-01251/ 00014 00015 /* 00016 Refrence: 00017 https://os.mbed.com/users/MikamiUitOpen/code/UIT_Sounder_OnOff/ 00018 by 不韋 呂 さん(Mikami-san) 00019 */ 00020 00021 #ifndef MBED_PIEZOBZ_H 00022 #define MBED_PIEZOBZ_H 00023 00024 #include "mbed.h" 00025 00026 /** Interface for Piezo Buzzer 00027 * 00028 * @code 00029 * #include "mbed.h" 00030 * #include "piezo_bz.h" 00031 * 00032 * PIEZO_BZ bz(D8, 3000U, 500U); // 3kHz 0.5 sec duty 00033 * 00034 * int main() { 00035 * while(1) { 00036 * bz.start(); 00037 * wait(5.0f); 00038 * bz.stop(); 00039 * wait(1.0f); 00040 * } 00041 * } 00042 * 00043 * @endcode 00044 */ 00045 00046 #define CONTINUOUS_MODE 0U 00047 00048 /** Piezo Buzzer class 00049 */ 00050 class PIEZO_BZ 00051 { 00052 public: 00053 00054 /** Create a Piezo Buzzer instance 00055 * 00056 * @param pin for Piezo Buzzer (another pin connect GND) 00057 * @param Buzzer frequency [Hz] 00058 * @param Duration for ringing time and rest time (duty 50%) [mS] 00059 * on_off_time = 0 -> Continuous mode 00060 */ 00061 PIEZO_BZ(PinName pin, uint32_t freq, uint32_t on_off_time); 00062 00063 /** Destructor of Piezo Buzzer 00064 */ 00065 virtual ~PIEZO_BZ(); 00066 00067 /** Start Buzzer 00068 */ 00069 void start(void); 00070 00071 /** Stop Buzzer 00072 */ 00073 void stop(void); 00074 00075 /** Change buzzer frequency 00076 * @param Buzzer frequency [Hz] 00077 */ 00078 void change_frequency(uint32_t freq); 00079 00080 /** Change On-Off duration 00081 * @param Duration for ringing time and rest time (duty 50%) [mS] 00082 */ 00083 void change_on_off(uint32_t on_off_time); 00084 00085 private: 00086 void create_freq_irq(void); 00087 void create_onoff_irq(void); 00088 00089 DigitalOut _pin; 00090 Ticker _t0; 00091 Ticker _t1; 00092 uint32_t freq; 00093 uint32_t t_onoff; 00094 bool out; 00095 bool flag_onoff; 00096 bool flag_run; 00097 bool flag_continuous; 00098 }; 00099 00100 #endif // MBED_PIEZOBZ_H
Generated on Thu Aug 25 2022 13:50:54 by
1.7.2