/ TrellisM4_Simple_MIDI_UART / code.py
code.py
1 # SPDX-FileCopyrightText: 2018 John Park for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 # Simple example of sending MIDI via UART to classic DIN-5 (not USB) synth 6 7 import adafruit_trellism4 8 from rainbowio import colorwheel 9 import board 10 import busio 11 midiuart = busio.UART(board.SDA, board.SCL, baudrate=31250) 12 print("MIDI UART EXAMPLE") 13 14 trellis = adafruit_trellism4.TrellisM4Express() 15 16 17 for x in range(trellis.pixels.width): 18 for y in range(trellis.pixels.height): 19 pixel_index = (((y * 8) + x) * 256 // 2) 20 trellis.pixels[x, y] = colorwheel(pixel_index & 255) 21 22 current_press = set() 23 24 while True: 25 pressed = set(trellis.pressed_keys) 26 27 for press in pressed - current_press: 28 x, y = press 29 print("Pressed:", press) 30 noteval = 36 + x + (y * 8) 31 midiuart.write(bytes([0x90, noteval, 100])) 32 33 for release in current_press - pressed: 34 x, y = release 35 print("Released:", release) 36 noteval = 36 + x + (y * 8) 37 midiuart.write(bytes([0x90, noteval, 0])) # note off 38 39 current_press = pressed