mirror of
https://github.com/ashstrahle/Pi-Pico-ExpressionPedal2Midi.git
synced 2025-12-31 19:49:51 +10:00
update
This commit is contained in:
19
main.py
19
main.py
@@ -22,11 +22,15 @@ cc_max = 97 # Maximum desired CC output (only want fader to go to unity gain - h
|
|||||||
exp_min = 65535
|
exp_min = 65535
|
||||||
exp_max = 0
|
exp_max = 0
|
||||||
|
|
||||||
exp_previous = 0
|
cc_previous = 0
|
||||||
|
|
||||||
# This function translates the expression pedal value to the equivalent CC value
|
# This function translates the expression pedal value to the equivalent CC value
|
||||||
def translate(exp_val):
|
def translate(exp_val):
|
||||||
|
if exp_max - exp_min > 40000:
|
||||||
ret = int((((exp_val - exp_min) * (cc_max - cc_min)) / (exp_max - exp_min)) + cc_min)
|
ret = int((((exp_val - exp_min) * (cc_max - cc_min)) / (exp_max - exp_min)) + cc_min)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
if ret > 0:
|
if ret > 0:
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
@@ -34,16 +38,17 @@ def translate(exp_val):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
exp_current = exp.read_u16()
|
exp_current = exp.read_u16()
|
||||||
|
cc_current = translate(exp_current)
|
||||||
if exp_current > exp_max:
|
if exp_current > exp_max:
|
||||||
exp_max = exp_current
|
exp_max = exp_current
|
||||||
elif exp_current < exp_min:
|
elif exp_current < exp_min:
|
||||||
exp_min = exp_current
|
exp_min = exp_current
|
||||||
|
|
||||||
if exp_current != exp_previous and exp_max - exp_min > 40000:
|
if cc_current != cc_previous:
|
||||||
led.value(1) # Turn led on
|
led.value(1) # Turn led on
|
||||||
cc_val = translate(exp_current)
|
uart.write(ustruct.pack("bbb",ControlChange + midi_channel - 1,cc,cc_current))
|
||||||
uart.write(ustruct.pack("bbb",ControlChange + midi_channel - 1,cc,cc_val))
|
|
||||||
led.value(0) # Turn led off
|
led.value(0) # Turn led off
|
||||||
exp_previous = exp_current
|
cc_previous = cc_current
|
||||||
print("Writing Midi Channel: {}, ControlChange: {}, Value {}. Exp Pedal: cur: {}, min: {}, max: {}".format(midi_channel, cc, cc_val, exp_current, exp_min, exp_max))
|
print("Writing Midi Channel: {}, ControlChange: {}, Value {}. Exp Pedal: cur: {}, min: {}, max: {}".format(midi_channel, cc, cc_current, exp_current, exp_min, exp_max))
|
||||||
time.sleep(0.05)
|
# else:
|
||||||
|
# time.sleep(0.05)
|
||||||
Reference in New Issue
Block a user