/ MIDI_FeatherWing / code.py
code.py
1 # SPDX-FileCopyrightText: 2021 John Park for Adafruit Industries 2 # SPDX-License-Identifier: MIT 3 # midi_UARToutdemo.py - demonstrates sending MIDI notes 4 5 import time 6 import board 7 import busio 8 import adafruit_midi 9 10 from adafruit_midi.control_change import ControlChange 11 from adafruit_midi.note_off import NoteOff 12 from adafruit_midi.note_on import NoteOn 13 14 uart = busio.UART(board.TX, board.RX, baudrate=31250, timeout=0.001) # init UART 15 midi_in_channel = 2 16 midi_out_channel = 1 17 midi = adafruit_midi.MIDI( 18 midi_in=uart, 19 midi_out=uart, 20 in_channel=(midi_in_channel - 1), 21 out_channel=(midi_out_channel - 1), 22 debug=False, 23 ) 24 note_hold = 0.85 25 rest = note_hold / 5 26 27 print("MIDI Out demo") 28 print("Default output channel:", midi.out_channel + 1) 29 30 while True: 31 # midi.send(ControlChange(64, 0)) # sustain CC 32 midi.send(ControlChange(1, 0)) # modulation CC 33 34 midi.send(NoteOn(48, 20)) # play note 35 time.sleep(note_hold) # hold note 36 midi.send(NoteOff(48, 0)) # release note 37 time.sleep(rest) # rest 38 39 midi.send(NoteOn(55, 40)) 40 time.sleep(note_hold) 41 midi.send(NoteOff(55, 0)) 42 time.sleep(rest) 43 44 midi.send(NoteOn(51, 60)) 45 time.sleep(note_hold) 46 midi.send(NoteOff(51, 0)) 47 time.sleep(rest) 48 49 midi.send(NoteOn(58, 80)) 50 time.sleep(note_hold) 51 midi.send(NoteOff(58, 0)) 52 time.sleep(rest) 53 54 # midi.send(ControlChange(64, 32)) 55 midi.send(ControlChange(1, 127)) 56 57 midi.send(NoteOn(48, 20)) # play note 58 time.sleep(note_hold) # hold note 59 midi.send(NoteOff(48, 0)) # release note 60 time.sleep(rest) # rest 61 62 midi.send(NoteOn(55, 40)) 63 time.sleep(note_hold) 64 midi.send(NoteOff(55, 0)) 65 time.sleep(rest) 66 67 midi.send(NoteOn(51, 60)) 68 time.sleep(note_hold) 69 midi.send(NoteOff(51, 0)) 70 time.sleep(rest) 71 72 midi.send(NoteOn(50, 80)) 73 time.sleep(note_hold) 74 midi.send(NoteOff(50, 0)) 75 time.sleep(rest)