EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 98

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 6 Buzzer
98
www.freenove.com
support@freenove.com
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).
def alertor():
p. start(50)
for x in 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.
def stopAlertor():
p. stop()

Table of Contents