The sound of the active buzzer is fixed, the operating voltage is constant, changing the time of the power off to obtain a different length of sound, such as continuous, fast short, slow long sound (similar to Morse Telegraph) to distinguish different alarm information.
Simply put, the active buzzer can only emit one sound because its frequency is fixed. can only be differentiated according to the different intervals of the sound.
For example, the alarm clock is: drip ~ drip ~ Drip ~.
As long as the power is ringing, we just have to control the power of the time is good.
#include"mbed.h"pwmout PWM1 (pb_13);intMain () { while(1) {PWM1=1;//rangWait0.1);//Ring 0.1sPWM1 =0;//Not ringingWait0.1);//No sound 0.1sPWM1 =1;//Ring AgainWait0.1);//Ring 0.1sPWM1 =0;//Not ringingWait0.6);//No sound 0.6s }}//End Main
The above can be achieved, drop 0.1s drops 0.1s (0.6s after) drops 0.1s 0.1s (0.6s) drops 0.1s drops 0.1s
The human ear sounds like the usual alarm clock drip ~ drip ~ drip ~ effect.
Here the PWM wave, replaced by Digitalout is the same, the PWM wave does not have any special significance.
I'm just testing pwm for what effect No.
Change the frequency of the PWM wave, the tone of the buzzer does not change.
Changing the size of the PWM wave, such as the pwm1=0.5, emits an unstable, shaky sound that doesn't work.
So the active buzzer just can ring, sound fixed.
The level =1 is ringing, =0 does not ring.
Cannot upload the recording, the previous picture:
STM32 using active buzzer to realize alarm clock sound