From 1d10babecfbd3c3609b6ee89d8fcb34486d331a0 Mon Sep 17 00:00:00 2001 From: Noe Ruiz Date: Fri, 1 Apr 2022 10:14:40 -0400 Subject: [PATCH] adding code for midi foot pedal code for midi foot pedal --- MIDI_Foot_Pedal/code.py | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 MIDI_Foot_Pedal/code.py diff --git a/MIDI_Foot_Pedal/code.py b/MIDI_Foot_Pedal/code.py new file mode 100755 index 000000000..54c39ece9 --- /dev/null +++ b/MIDI_Foot_Pedal/code.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT + +import board +import usb_midi +import adafruit_midi +import simpleio +from analogio import AnalogIn +from adafruit_midi.control_change import ControlChange +from adafruit_midi.pitch_bend import PitchBend + +# midi setup +midi = adafruit_midi.MIDI( + midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0 +) + +# potentiometer setup +mod_pot = AnalogIn(board.A0) + +# function to read analog input +def val(pin): + return pin.value + +# variables for last read value +# defaults to 0 +# no pitchbend is 8192 +mod_val2 = 0 + +while True: + + # uncomment below to print potentiometer values in the REPL + # print("{}".format(mod_pot.value)) + + # map range of potentiometer input to midi values + mod_val1 = round(simpleio.map_range(val(mod_pot), 41200, 58500, 0, 127)) + + # if modulation value is updated... + if abs(mod_val1 - mod_val2) > 2: + # update mod_val2 + mod_val2 = mod_val1 + # create integer + modulation = int(mod_val2) + # create CC message + modWheel = ControlChange(1, modulation) + # send CC message + midi.send(modWheel) +