4
4
Give your suit an sound-reactive upgrade with Circuit
5
5
Playground Bluefruit & Neopixels. Set color and animation
6
6
mode using the Bluefruit LE Connect app.
7
-
7
+
8
8
Author: Collin Cunningham for Adafruit Industries, 2019
9
9
"""
10
+ # pylint: disable=global-statement
10
11
11
12
import time
12
13
import array
@@ -78,25 +79,25 @@ def volume_color(volume):
78
79
input_ceiling = input_floor + 500
79
80
peak = 0
80
81
81
- def wheel (pos ):
82
+ def wheel (wheel_pos ):
82
83
# Input a value 0 to 255 to get a color value.
83
84
# The colours are a transition r - g - b - back to r.
84
- if pos < 0 or pos > 255 :
85
+ if wheel_pos < 0 or wheel_pos > 255 :
85
86
r = g = b = 0
86
- elif pos < 85 :
87
- r = int (pos * 3 )
88
- g = int (255 - pos * 3 )
87
+ elif wheel_pos < 85 :
88
+ r = int (wheel_pos * 3 )
89
+ g = int (255 - wheel_pos * 3 )
89
90
b = 0
90
- elif pos < 170 :
91
- pos -= 85
92
- r = int (255 - pos * 3 )
91
+ elif wheel_pos < 170 :
92
+ wheel_pos -= 85
93
+ r = int (255 - wheel_pos * 3 )
93
94
g = 0
94
- b = int (pos * 3 )
95
+ b = int (wheel_pos * 3 )
95
96
else :
96
- pos -= 170
97
+ wheel_pos -= 170
97
98
r = 0
98
- g = int (pos * 3 )
99
- b = int (255 - pos * 3 )
99
+ g = int (wheel_pos * 3 )
100
+ b = int (255 - wheel_pos * 3 )
100
101
return (r , g , b )
101
102
102
103
def rainbow_cycle (wait ):
@@ -114,7 +115,7 @@ def audio_meter():
114
115
115
116
# Compute scaled logarithmic reading in the range 0 to NUM_PIXELS
116
117
c = log_scale (constrain (magnitude , input_floor , input_ceiling ),
117
- input_floor , input_ceiling , 0 , NUM_PIXELS )
118
+ input_floor , input_ceiling , 0 , NUM_PIXELS )
118
119
119
120
# Light up pixels that are below the scaled and interpolated magnitude.
120
121
pixels .fill (0 )
@@ -135,7 +136,7 @@ def audio_meter():
135
136
136
137
def larsen_set (index , color ):
137
138
if index < 0 :
138
- return
139
+ return
139
140
else :
140
141
pixels [index ] = color
141
142
@@ -144,9 +145,9 @@ def larsen(wait):
144
145
global direction
145
146
146
147
color_dark = (int (user_color [0 ]/ 8 ), int (user_color [1 ]/ 8 ),
147
- int (user_color [2 ]/ 8 ))
148
+ int (user_color [2 ]/ 8 ))
148
149
color_med = (int (user_color [0 ]/ 2 ), int (user_color [1 ]/ 2 ),
149
- int (user_color [2 ]/ 2 ))
150
+ int (user_color [2 ]/ 2 ))
150
151
151
152
larsen_set (pos - 2 , color_dark )
152
153
larsen_set (pos - 1 , color_med )
@@ -182,7 +183,7 @@ def solid():
182
183
183
184
def map_value (value , in_min , in_max , out_min , out_max ):
184
185
return out_min + (out_max - out_min ) * ((value - in_min )
185
- / (in_max - in_min ))
186
+ / (in_max - in_min ))
186
187
187
188
def change_speed (val ):
188
189
global speed
@@ -234,4 +235,4 @@ def change_speed(val):
234
235
elif mode == 2 :
235
236
larsen (map_value (speed , 10.0 , 0.0 , 0.01 , 0.3 ))
236
237
elif mode == 3 :
237
- solid ()
238
+ solid ()
0 commit comments