Buzzer - passive buzzer¶
from robot_hat import PWM, Buzzer, Music pwm = PWM("A0") # create a pwm object buzzer = Buzzer(pwm) # create a Buzzer object with PWM object music = Music() # create music object buzzer.play(music.note("Low C"), music.beat(1)) # play low C for 1 beat buzzer.play(music.note("Middle C#")) # play middle C sharp buzzer.off() # turn buzzer off
class robot_hat.Buzzer(pwm): Create a Buzzer object associated with the given pwm object. This will allow you to control the buzzer.
on- Turn the buzzer on with a square wave.
off- Turn the buzzer off.
freq- Set the frequency of the square wave.
play- Make the buzzer sound at a specific frequency and stop at a ms delay time.
Buzzer.play(freq, ms) Buzzer.play(freq)