55import board
66import usb_midi
77import adafruit_midi
8- from digitalio import DigitalInOut , Direction , Pull
9- from adafruit_midi .control_change import ControlChange
8+ from digitalio import DigitalInOut , Direction
109from adafruit_midi .note_off import NoteOff
1110from adafruit_midi .note_on import NoteOn
12- from adafruit_midi .pitch_bend import PitchBend
1311import neopixel
1412
1513# enable external power pin
2321BRIGHTNESS = 1
2422PIN = board .EXTERNAL_NEOPIXELS
2523ORDER = neopixel .BGR
26- pixels = neopixel .NeoPixel (PIN , NUMPIXELS , brightness = BRIGHTNESS , auto_write = False , pixel_order = ORDER )
24+ pixels = neopixel .NeoPixel (PIN , NUMPIXELS , brightness = BRIGHTNESS ,
25+ auto_write = False , pixel_order = ORDER )
2726
2827# Matrix layout
2928MATRIX_ROWS = 6
@@ -92,26 +91,26 @@ def note_to_matrix(note):
9291 NOTE_OFFSET determines which note maps to (row=0, col=0).
9392 """
9493 offset_note = note - NOTE_OFFSET
95- row = (offset_note // MATRIX_COLS ) % MATRIX_ROWS
96- col = offset_note % MATRIX_COLS
97- return row , col
94+ r = (offset_note // MATRIX_COLS ) % MATRIX_ROWS
95+ c = offset_note % MATRIX_COLS
96+ return r , c
9897
99- def matrix_to_pixel (row , col ):
98+ def matrix_to_pixel (r , c ):
10099 """
101100 Convert a (row, col) matrix position to a physical pixel index,
102101 accounting for zigzag wiring.
103102 Even rows (0, 2, 4) run left to right.
104103 Odd rows (1, 3, 5) run right to left.
105104 """
106- if row % 2 == 0 :
107- return row * MATRIX_COLS + col # Left to right
105+ if r % 2 == 0 :
106+ return r * MATRIX_COLS + c # Left to right
108107 else :
109- return row * MATRIX_COLS + (MATRIX_COLS - 1 - col ) # Right to left
108+ return r * MATRIX_COLS + (MATRIX_COLS - 1 - c ) # Right to left
110109
111110def note_to_pixel (note ):
112111 """Map a MIDI note directly to a physical pixel index via the matrix."""
113- row , col = note_to_matrix (note )
114- return matrix_to_pixel (row , col )
112+ r , c = note_to_matrix (note )
113+ return matrix_to_pixel (r , c )
115114
116115def note_to_name (note ):
117116 """Return a human-readable note name and octave, e.g. 'C2' for note 36."""
@@ -127,10 +126,10 @@ def color_for_note(note):
127126 offset_note = note - NOTE_OFFSET
128127 return BASE_COLORS [offset_note % len (BASE_COLORS )]
129128
130- def color_wipe (color , delay = 0.01 ):
129+ def color_wipe (c , delay = 0.01 ):
131130 """Wipe a color across the strip one LED at a time."""
132131 for i in range (NUMPIXELS ):
133- pixels [i ] = color
132+ pixels [i ] = c
134133 pixels .show ()
135134 time .sleep (delay )
136135
@@ -145,22 +144,22 @@ def update_fades():
145144 """Call this every loop iteration to advance any active fades."""
146145 now = time .monotonic ()
147146 completed = []
148- for pixel_index , state in fading_pixels .items ():
147+ for pix_index , state in fading_pixels .items ():
149148 step_delay = FADE_DURATION / FADE_STEPS
150149 if now - state ["last_time" ] >= step_delay :
151150 state ["step" ] += 1
152151 state ["last_time" ] = now
153152 if state ["step" ] >= FADE_STEPS :
154- pixels [pixel_index ] = (0 , 0 , 0 )
153+ pixels [pix_index ] = (0 , 0 , 0 )
155154 pixels .show ()
156- completed .append (pixel_index )
155+ completed .append (pix_index )
157156 else :
158157 r , g , b = state ["color" ]
159158 factor = (FADE_STEPS - state ["step" ]) / FADE_STEPS
160- pixels [pixel_index ] = (int (r * factor ), int (g * factor ), int (b * factor ))
159+ pixels [pix_index ] = (int (r * factor ), int (g * factor ), int (b * factor ))
161160 pixels .show ()
162- for pixel_index in completed :
163- del fading_pixels [pixel_index ]
161+ for pix_index in completed :
162+ del fading_pixels [pix_index ]
164163
165164# Run boot sequence on startup
166165boot_sequence ()
@@ -178,7 +177,7 @@ def update_fades():
178177 del fading_pixels [pixel_index ]
179178 pixels [pixel_index ] = color
180179 pixels .show ()
181- print (f"Note ON: { note_name } ({ msg .note } ) -> Row { row } , Col { col } , Pixel { pixel_index } , Color { color } , Channel { msg . channel + 1 } " )
180+ print (f"Note ON: { note_name } ({ msg .note } ) Pixel { pixel_index } , Color { color } " )
182181
183182 elif isinstance (msg , NoteOff ) or (isinstance (msg , NoteOn ) and msg .velocity == 0 ):
184183 pixel_index = note_to_pixel (msg .note )
@@ -190,7 +189,7 @@ def update_fades():
190189 "step" : 0 ,
191190 "last_time" : time .monotonic ()
192191 }
193- print (f"Note OFF: { note_name } ({ msg .note } ) -> Row { row } , Col { col } , Pixel { pixel_index } fading, Channel { msg . channel + 1 } " )
192+ print (f"Note OFF: { note_name } ({ msg .note } ) Pixel { pixel_index } fading" )
194193
195194 # Advance all active fades each loop iteration
196195 update_fades ()
0 commit comments