Skip to main content

Buzzer

Eliobot buzzer


Le buzzer d'Eliobot est un buzzer passif, il peut donc émettre des sons sur une grande plage de fréquence un peu comme les vieux téléphones.

Use with Elioblocs

To use Eliobot's buzzer on Elioblocs, we use blocks from the catégorie son category to play a sound.

Using with Python

To play notes in Python, we use the IO17 pin as a PWM output to be able to reproduce the desired frequency.

To play music, simply repeat the desired frequencies like in a score.

Elioblocs example

exemple buzzer elioblocs

Here, we play the note Do for 1 second and start again infinitely.


Python Example

With the library elio.py

import board
import pwmio
from elio import Buzzer

buzzer_pin = pwmio.PWMOut(board.IO17, variable_frequency=True)
buzzer = Buzzer(buzzer_pin)

NOTES = {
"Do": 262,
"silence": 0.1,
}

while True:
buzzer.play_note("Do", 1, NOTES, 80) # Joue Do pendant 1 seconde
buzzer.play_note("silence", 1, NOTES, 0) # Pause d'1 seconde

Here, we play the note Do for 1 second and start again infinitely.


Without the library elio.py

import board
import pwmio
import time

buzzer = pwmio.PWMOut(board.IO17, variable_frequency=True)

while True:
buzzer.frequency = 262 # Fréquence de la note Do
buzzer.duty_cycle = 32768 # 50% duty cycle pour émettre le son
time.sleep(1)
buzzer.duty_cycle = 0 # Arrête le son
time.sleep(1)

Same principle, but directly controlling the frequency and duty cycle of the PWM.