/ examples / midi_simpletest.py
midi_simpletest.py
 1  # simple_test
 2  import time
 3  import random
 4  import usb_midi
 5  import adafruit_midi
 6  from adafruit_midi.control_change import ControlChange
 7  from adafruit_midi.note_off import NoteOff
 8  from adafruit_midi.note_on import NoteOn
 9  from adafruit_midi.pitch_bend import PitchBend
10  
11  midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
12  
13  print("Midi test")
14  
15  # Convert channel numbers at the presentation layer to the ones musicians use
16  print("Default output channel:", midi.out_channel + 1)
17  print(
18      "Listening on input channel:",
19      midi.in_channel + 1 if midi.in_channel is not None else None,
20  )
21  
22  while True:
23      midi.send(NoteOn(44, 120))  # G sharp 2nd octave
24      time.sleep(0.25)
25      a_pitch_bend = PitchBend(random.randint(0, 16383))
26      midi.send(a_pitch_bend)
27      time.sleep(0.25)
28      # note how a list of messages can be used
29      midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
30      time.sleep(0.5)