Skip to content

Commit 7817031

Browse files
authored
Merge pull request #2131 from adafruit/midi_foot_pedal
adding code for midi foot pedal
2 parents b3c5d13 + c7dff35 commit 7817031

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

MIDI_Foot_Pedal/code.py

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

0 commit comments

Comments
 (0)