Skip to content

Commit a0a1f64

Browse files
committed
fixed old comments, simpler chase_down loop code
1 parent ee0dbf8 commit a0a1f64

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

Ambient_Color_Control_Pad/ambient_color_control_pad.py

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Ambient Color Control Pad
22
# NeoTrellis to select colors of NeoPixel strip
3-
# NeoTrellis connected to Feather M4 (need the extra memory) SCL, SDA
3+
# NeoTrellis connected to Feather M4 (need the extra memory vs. M0) SCL, SDA
44
# NeoPixel 120 strip connected to pin D5
55
# NeoPixel strip powered over 5V 2A DC wall power supply
6-
# Latching on/off button RGB connects En to GND, LED to D13
6+
# On/off button RGB connects En to GND, LED to D13
77

88
import time
99
import board
@@ -17,8 +17,6 @@
1717
button_LED.direction = Direction.OUTPUT
1818
button_LED.value = True
1919

20-
print("Ambient_Color_Controller.py")
21-
2220
pixel_pin = board.D5
2321
num_pixels = 120
2422

@@ -27,7 +25,7 @@
2725
# create the i2c object for the trellis
2826
i2c_bus = busio.I2C(SCL, SDA)
2927

30-
# create the trellis
28+
# create the trellis object
3129
trellis = NeoTrellis(i2c_bus)
3230

3331
# color definitions
@@ -49,7 +47,7 @@
4947
WHITE_GREEN = (80, 120, 100)
5048

5149

52-
COLORS = [ # normal button color states
50+
COLORS = [ # pixel colors
5351
RED, ORANGE, YELLOW, YELLOW_GREEN,
5452
GREEN, CYAN, LIGHT_BLUE, BLUE,
5553
PURPLE, PINK, ROUGE, WHITE,
@@ -67,27 +65,26 @@ def dimmed_colors(color_values):
6765

6866
# this will be called when button events are received
6967
def blink(event):
70-
# turn the LED on when a rising edge is detected
71-
# do the fade for the NeoPixel strip
68+
# turn the trellis LED on when a rising edge is detected
69+
# do the chase for the NeoPixel strip
7270
if event.edge == NeoTrellis.EDGE_RISING:
7371
trellis.pixels[event.number] = dimmed_colors(COLORS[event.number])
74-
for fade_i in range(num_pixels): # fade off
75-
pixels[fade_i] = (OFF)
72+
for chase_off in range(num_pixels): # chase LEDs off
73+
pixels[chase_off] = (OFF)
7674
pixels.show()
7775
time.sleep(0.005)
78-
# for fade_i in range(num_pixels): #fade up
79-
reverse_fade_i = num_pixels - 1
80-
while reverse_fade_i >= 0: # fade backwards
81-
pixels[reverse_fade_i] = (COLORS[event.number])
82-
reverse_fade_i -= 1
76+
77+
for chase_on in range(num_pixels - 1, -1, -1): # chase LEDs on
78+
pixels[chase_on] = (COLORS[event.number])
8379
pixels.show()
8480
time.sleep(0.03)
85-
# turn the LED off when a rising edge is detected
81+
82+
# turn the trellis LED back to full color when a rising edge is detected
8683
elif event.edge == NeoTrellis.EDGE_FALLING:
8784
trellis.pixels[event.number] = COLORS[event.number]
8885

8986

90-
# boot up animation
87+
# boot up animation on trellis
9188
trellis.pixels.brightness = 0.2
9289
for i in range(16):
9390
# activate rising edge events on all keys
@@ -97,15 +94,16 @@ def blink(event):
9794
# set all keys to trigger the blink callback
9895
trellis.callbacks[i] = blink
9996

100-
# cycle the LEDs on startup
97+
# light the trellis LEDs on startup
10198
trellis.pixels[i] = COLORS[i]
10299
time.sleep(.05)
103100

104101
print(" Ambient Color Control Pad")
105102
print(" ---press a button to change the ambient color---")
103+
106104
while True:
107105

108106
# call the sync function call any triggered callbacks
109107
trellis.sync()
110-
# the trellis can only be read every 17 millisecons or so
108+
# the trellis can only be read every 17 milliseconds or so
111109
time.sleep(.02)

0 commit comments

Comments
 (0)