Chapter 6 Buzzer
98
In the while cycle of main function, when the button is pressed, subfunction alertor() will be called and the
alertor will issue a warning sound. The frequency curve of the alarm is based on the sine curve. We need to
calculate the sine value from 0 to 360 degree and multiply a certain value (here is 500) and plus the resonant
frequency of buzzer. We can set the PWM frequency through p.ChangeFrequency(toneVal).
d e f
alertor
():
p
.
start
(
50
)
f o r
x
i n
range
(
0
,
361
):
sinVal
=
math
.
sin
(
x
*
(
math
.
pi
/
180.0
) )
toneVal
=
2000
+
sinVal
*
500
p
.
ChangeFrequency
(
toneVal
)
time
.
sleep
(
0.001
)
When the button is released, the buzzer will be closed.
d e f
stopAlertor
():
p
.
stop
()
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...