Skip to content

Commit 1d10bab

Browse files
committed
adding code for midi foot pedal
code for midi foot pedal
1 parent b3c5d13 commit 1d10bab

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

MIDI_Foot_Pedal/code.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import usb_midi
6+
import adafruit_midi
7+
import simpleio
8+
from analogio import AnalogIn
9+
from adafruit_midi.control_change import ControlChange
10+
from adafruit_midi.pitch_bend import PitchBend
11+
12+
# midi setup
13+
midi = adafruit_midi.MIDI(
14+
midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0
15+
)
16+
17+
# potentiometer setup
18+
mod_pot = AnalogIn(board.A0)
19+
20+
# function to read analog input
21+
def val(pin):
22+
return pin.value
23+
24+
# variables for last read value
25+
# defaults to 0
26+
# no pitchbend is 8192
27+
mod_val2 = 0
28+
29+
while True:
30+
31+
# uncomment below to print potentiometer values in the REPL
32+
# print("{}".format(mod_pot.value))
33+
34+
# map range of potentiometer input to midi values
35+
mod_val1 = round(simpleio.map_range(val(mod_pot), 41200, 58500, 0, 127))
36+
37+
# if modulation value is updated...
38+
if abs(mod_val1 - mod_val2) > 2:
39+
# update mod_val2
40+
mod_val2 = mod_val1
41+
# create integer
42+
modulation = int(mod_val2)
43+
# create CC message
44+
modWheel = ControlChange(1, modulation)
45+
# send CC message
46+
midi.send(modWheel)
47+

0 commit comments

Comments
 (0)