Created
September 5, 2023 12:20
-
-
Save ypelletier/025dae81884e083aca78c04160ee9375 to your computer and use it in GitHub Desktop.
MIDI OUT avec Raspberry Pi Pico. Mélodie à la basse sur le canal 1, et batterie sur le canal 10.
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
''' | |
MIDI OUT avec Raspberry Pi Pico. Mélodie à la basse sur le canal 1, et batterie | |
sur le canal 10. | |
Pour plus d'informations: | |
https://electroniqueamateur.blogspot.com/2023/09/midi-out-avec-le-raspberry-pi-pico.html | |
''' | |
import machine | |
import time | |
uart = machine.UART(1,31250) # UART numéro 1, 31 250 bauds. | |
#notes à jouer successivement | |
basse = [36,36,40,40,43,43,45,43] | |
batterie = [36,42,38,42,36,42,38,42] | |
pattern = [0,0,0,0,5,5,0,0,7,5,0,7] | |
def noteOn (channel,note,velocity): | |
uart.write(bytes([0x90 + channel - 1])) | |
uart.write(bytes([note])) | |
uart.write(bytes([velocity])) | |
def noteOff (channel,note): | |
uart.write(bytes([0x80 + channel - 1])) | |
uart.write(bytes([note])) | |
uart.write(bytes([0])) | |
def programChange (channel, program): | |
uart.write(bytes([0xC0 + channel - 1])) | |
uart.write(bytes([program - 1])) | |
programChange(1,37) # canal 1: basse | |
while True: | |
for i in range(12): | |
for x in range(8): | |
noteOn(1,basse[x]+pattern[i],110) | |
noteOn(10,batterie[x],127) | |
time.sleep(0.2) | |
noteOff(1,basse[x]+pattern[i]) | |
noteOff(10,batterie[x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment