1
1
# Ambient Color Control Pad
2
2
# 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
4
4
# NeoPixel 120 strip connected to pin D5
5
5
# 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
7
7
8
8
import time
9
9
import board
17
17
button_LED .direction = Direction .OUTPUT
18
18
button_LED .value = True
19
19
20
- print ("Ambient_Color_Controller.py" )
21
-
22
20
pixel_pin = board .D5
23
21
num_pixels = 120
24
22
27
25
# create the i2c object for the trellis
28
26
i2c_bus = busio .I2C (SCL , SDA )
29
27
30
- # create the trellis
28
+ # create the trellis object
31
29
trellis = NeoTrellis (i2c_bus )
32
30
33
31
# color definitions
49
47
WHITE_GREEN = (80 , 120 , 100 )
50
48
51
49
52
- COLORS = [ # normal button color states
50
+ COLORS = [ # pixel colors
53
51
RED , ORANGE , YELLOW , YELLOW_GREEN ,
54
52
GREEN , CYAN , LIGHT_BLUE , BLUE ,
55
53
PURPLE , PINK , ROUGE , WHITE ,
@@ -67,27 +65,26 @@ def dimmed_colors(color_values):
67
65
68
66
# this will be called when button events are received
69
67
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
72
70
if event .edge == NeoTrellis .EDGE_RISING :
73
71
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 )
76
74
pixels .show ()
77
75
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 ])
83
79
pixels .show ()
84
80
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
86
83
elif event .edge == NeoTrellis .EDGE_FALLING :
87
84
trellis .pixels [event .number ] = COLORS [event .number ]
88
85
89
86
90
- # boot up animation
87
+ # boot up animation on trellis
91
88
trellis .pixels .brightness = 0.2
92
89
for i in range (16 ):
93
90
# activate rising edge events on all keys
@@ -97,15 +94,16 @@ def blink(event):
97
94
# set all keys to trigger the blink callback
98
95
trellis .callbacks [i ] = blink
99
96
100
- # cycle the LEDs on startup
97
+ # light the trellis LEDs on startup
101
98
trellis .pixels [i ] = COLORS [i ]
102
99
time .sleep (.05 )
103
100
104
101
print (" Ambient Color Control Pad" )
105
102
print (" ---press a button to change the ambient color---" )
103
+
106
104
while True :
107
105
108
106
# call the sync function call any triggered callbacks
109
107
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
111
109
time .sleep (.02 )
0 commit comments