Created
September 5, 2023 12:10
-
-
Save ypelletier/f4fb74f84980e072b1fd496769aa3292 to your computer and use it in GitHub Desktop.
Simple démonstration d'envoi de messages MIDI par un Raspbery Pi Pico: la note Do4 est jouée pendant 2 secondes avec un son de trompette.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Simple démonstration d'envoi de messages MIDI par un Raspbery Pi Pico: | |
la note Do4 est jouée pendant 2 secondes avec un son de trompette. | |
Pour plus d'informations: | |
https://electroniqueamateur.blogspot.com/2023/09/midi-out-avec-le-raspberry-pi-pico.html | |
''' | |
import machine | |
import time | |
# initialisation de la communication UART | |
uart = machine.UART(1,31250) # UART numéro 1, 31 250 bauds | |
# nous assignons un son de trompette au canal 1 | |
uart.write(bytes([0xC0])) # "program change", canal 1 | |
uart.write(bytes([56])) # instrument numéro 57: trompette | |
# nous jouons la note "Do 3" | |
uart.write(bytes([0x90])) # message "note on", canal 1 | |
uart.write(bytes([60])) # note #60: do4 | |
uart.write(bytes([127])) # vélocité (0 à 127): volume maximal | |
time.sleep(2) # on maintient la note pendant 2 secondes. | |
# nous cessons de jouer la note | |
uart.write(bytes([0x80])) # message "note off", canal 1 | |
uart.write(bytes([60])) # note #60: do4 | |
uart.write(bytes([0])) # vélocité |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment