# bi directional midi example for Adafruit MIDI Featherwing on M4 Express. import board import busio import time #midiuart = busio.UART(board.SDA, board.SCL, baudrate=31250) midiuart = busio.UART(board.TX, board.RX, baudrate=31250, timeout=0) print("MIDI UART EXAMPLE") toggleState = "off" lastTickTime = time.time() while True: data = midiuart.read(1) # read up to 32 bytes if data is not None: print("incoming"+str(data)) currentTime = time.time() elapsedTickTime = currentTime - lastTickTime if (elapsedTickTime > 1.0): print("tick",str(currentTime)) lastTickTime = currentTime if (toggleState == "off"): toggleState = "on" midiuart.write(bytes([0x90, 0x3C, 0x40])) else: toggleState = "off" midiuart.write(bytes([0x80, 0x3C, 0x40]))