speaker
carte BBC micro:bit
Utilisation d'un speaker
kit Grove

Schéma du montage (exemple).

code Python (exemple 1)

from microbit import
from utime import sleep_us
# This example requires a speaker/buzzer/headphones connected to P0 and GND.
def note(duree):
    for i in range(
        pin0.write_digital
        sleep_us(1136
        pin0.write_digital
        sleep_us(1136
		
while True:
    note(100)	

code Python (exemple 2) module music

from microbit import
import music
# This example requires a speaker/buzzer/headphones connected to P0 and GND.
music.set_tempo(bpm=180)
music.play("A1:1")	

Tableau de correspondance entre les fréquences et les notes de musique.

frequences et notes

CC BY SA  ( Christophe Béasse - Mai 2019 )