Skip to content

Commit c7d7b5b

Browse files
authored
Merge pull request #2233 from jedgarpark/flying-fader
changed touch pin so it'll work on Feather RP2040 (was on A4, now on A3)
2 parents 1f0f36d + d9f892c commit c7d7b5b

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

Flying_Fader/code.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2022 John Park for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
# Motorized fader demo
4-
54
import time
65
import board
76
import pwmio
@@ -12,7 +11,7 @@
1211
from adafruit_debouncer import Debouncer
1312
from adafruit_motor import motor
1413

15-
MIDI_DEMO = False
14+
MIDI_DEMO = False # set to True to send MIDI CC
1615

1716
# optional MIDI setup
1817
if MIDI_DEMO:
@@ -22,7 +21,6 @@
2221
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
2322
fader_cc_number = 16
2423

25-
2624
# Button setup to store four saved values
2725
button_pins = (board.D10, board.D9, board.D6, board.D5)
2826
buttons = []
@@ -31,15 +29,14 @@
3129
tmp_pin.pull = Pull.UP
3230
buttons.append(Debouncer(tmp_pin))
3331

34-
saved_positions = (240, 180, 120, 40) # pre-saved positions for the buttons to call
32+
saved_positions = (230, 180, 120, 60) # pre-saved positions for the buttons to call
3533

3634
# Slide pot setup
3735
fader = analogio.AnalogIn(board.A0)
3836
fader_position = fader.value # ranges from 0-65535
3937
fader_pos = fader.value // 256 # make 0-255 range
4038
last_fader_pos = fader_pos
4139

42-
4340
# Motor setup
4441
PWM_PIN_A = board.D12 # pick any pwm pins on their own channels
4542
PWM_PIN_B = board.D11
@@ -50,7 +47,8 @@
5047
motor1 = motor.DCMotor(pwm_a, pwm_b)
5148

5249
# Touch setup pin goes from touch pin on slide pot to touch capable pin and then 1MΩ to gnd
53-
touch = touchio.TouchIn(board.A4)
50+
touch = touchio.TouchIn(board.A3)
51+
touch.threshold = touch.raw_value + 30 # tune for fader knob cap
5452

5553
# NeoPixel setup
5654
led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2, auto_write=True)
@@ -60,7 +58,6 @@ def clamp(num, min_value, max_value): # function for clamping motor throttle -1
6058
return max(min(num, max_value), min_value)
6159

6260
def go_to_position(new_position):
63-
6461
global fader_pos # pylint: disable=global-statement
6562
fader_pos = int(fader.value//256)
6663
while abs(fader_pos - new_position) > 2 :
@@ -90,11 +87,8 @@ def go_to_position(new_position):
9087
print("--__ Flying Fader Demo __--")
9188
print("\n"*4)
9289

93-
go_to_position(120)
94-
go_to_position(60)
95-
go_to_position(180)
96-
go_to_position(40)
97-
go_to_position(200)
90+
go_to_position(saved_positions[3]) # boot up demo
91+
go_to_position(saved_positions[0])
9892
time.sleep(.6)
9993

10094
current_saved_position = 0 # state to store which is current position from the list
@@ -114,10 +108,9 @@ def go_to_position(new_position):
114108
fader_pos = int((filter_amt * last_fader_pos) + ((1.0-filter_amt) * fader.value//256))
115109
led[0] = (fader_pos, 0, 0)
116110
if abs(fader_pos - last_fader_pos) > 1 : # do things in here, e.g. send MIDI CC
117-
fader_width = 90
111+
fader_width = 90 # for text visualization in serial output
118112
print("-" * (fader_width - int(fader_pos/3)), fader_pos, "-" * int(fader_pos/3), end='\r')
119113
last_fader_pos = fader_pos
120-
121114
if MIDI_DEMO:
122115
fader_cc = int(fader_pos / 2) # cc is 0-127
123116
midi.send(ControlChange(fader_cc_number, fader_cc))

0 commit comments

Comments
 (0)