Fix formatting issues
This commit is contained in:
parent
aecc9347c9
commit
08cb52fbea
14 changed files with 63 additions and 73 deletions
|
|
@ -70,9 +70,9 @@ state = bright
|
|||
|
||||
def set_color(index):
|
||||
index = max(min(index, index_max), index_bottom)
|
||||
if (index >= index_min):
|
||||
if index >= index_min:
|
||||
strip[0] = [index, int((index * 3) / 8), 0]
|
||||
elif (index < index_min):
|
||||
elif index < index_min:
|
||||
strip[0] = [index, int((index * 3.25) / 8), 0]
|
||||
|
||||
|
||||
|
|
@ -83,13 +83,13 @@ while True:
|
|||
current_time = time.monotonic()
|
||||
|
||||
# BRIGHT
|
||||
if (state == bright):
|
||||
if state == bright:
|
||||
flicker_msecs = random.randint(
|
||||
0, down_max_msecs - down_min_msecs) + down_min_msecs
|
||||
flicker_start = current_time
|
||||
index_start = index_end
|
||||
|
||||
if ((index_start > index_bottom) and (random.randint(0, 100) < index_bottom_percent)):
|
||||
if (index_start > index_bottom) and (random.randint(0, 100) < index_bottom_percent):
|
||||
index_end = random.randint(
|
||||
0, index_start - index_bottom) + index_bottom
|
||||
else:
|
||||
|
|
@ -98,7 +98,7 @@ while True:
|
|||
state = down
|
||||
|
||||
# DIM
|
||||
elif (state == dim):
|
||||
elif state == dim:
|
||||
flicker_msecs = random.randint(
|
||||
0, up_max_msecs - up_min_msecs) + up_min_msecs
|
||||
flicker_start = current_time
|
||||
|
|
@ -107,25 +107,25 @@ while True:
|
|||
state = down
|
||||
|
||||
# DIM_HOLD
|
||||
elif (state == dim_hold):
|
||||
elif state == dim_hold:
|
||||
# dividing flicker_msecs by 1000 to convert to milliseconds
|
||||
if (current_time >= (flicker_start + (flicker_msecs / 1000))):
|
||||
if (state == bright_hold):
|
||||
if current_time >= (flicker_start + (flicker_msecs / 1000)):
|
||||
if state == bright_hold:
|
||||
state = bright
|
||||
else:
|
||||
state = dim
|
||||
|
||||
# DOWN
|
||||
elif (state == down):
|
||||
elif state == down:
|
||||
# dividing flicker_msecs by 1000 to convert to milliseconds
|
||||
if (current_time < (flicker_start + (flicker_msecs / 1000))):
|
||||
if current_time < (flicker_start + (flicker_msecs / 1000)):
|
||||
set_color(index_start + int(((index_end - index_start) *
|
||||
(((current_time - flicker_start) * 1.0) / flicker_msecs))))
|
||||
else:
|
||||
set_color(index_end)
|
||||
|
||||
if (state == down):
|
||||
if (random.randint(0, 100) < dim_hold_percent):
|
||||
if state == down:
|
||||
if random.randint(0, 100) < dim_hold_percent:
|
||||
flicker_start = current_time
|
||||
flicker_msecs = random.randint(
|
||||
0, dim_hold_max_msecs - dim_hold_min_msecs) + dim_hold_min_msecs
|
||||
|
|
@ -133,7 +133,7 @@ while True:
|
|||
else:
|
||||
state = dim
|
||||
else:
|
||||
if (random.randint(0, 100) < bright_hold_percent):
|
||||
if random.randint(0, 100) < bright_hold_percent:
|
||||
flicker_start = current_time
|
||||
flicker_msecs = random.randint(
|
||||
0, bright_hold_max_msecs - bright_hold_min_msecs) + bright_hold_min_msecs
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ while True:
|
|||
signalMin = 65535
|
||||
signalMax = 0
|
||||
startTime = time.monotonic()
|
||||
while ((time.monotonic() - startTime) < sampleWindow):
|
||||
while (time.monotonic() - startTime) < sampleWindow:
|
||||
signal = mic.value
|
||||
if signal < signalMin:
|
||||
signalMin = signal
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
numpix = 5 # Number of NeoPixels
|
||||
import board
|
||||
import neopixel
|
||||
|
||||
numpix = 5 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
hue = 0 # Starting color
|
||||
hue = 0 # Starting color
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4)
|
||||
|
||||
|
||||
|
|
@ -13,9 +14,9 @@ def wheel(pos):
|
|||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0) or (pos > 255):
|
||||
return [0, 0, 0]
|
||||
elif (pos < 85):
|
||||
elif pos < 85:
|
||||
return [int(pos * 3), int(255 - (pos * 3)), 0]
|
||||
elif (pos < 170):
|
||||
elif pos < 170:
|
||||
pos -= 85
|
||||
return [int(255 - pos * 3), 0, int(pos * 3)]
|
||||
else:
|
||||
|
|
@ -27,5 +28,5 @@ while True: # Loop forever...
|
|||
for i in range(numpix):
|
||||
strip[i] = wheel((hue + i * 8) & 255)
|
||||
strip.write()
|
||||
time.sleep(0.02) # 20 ms = ~50 fps
|
||||
time.sleep(0.02) # 20 ms = ~50 fps
|
||||
hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255
|
||||
|
|
|
|||
|
|
@ -122,8 +122,7 @@ while True:
|
|||
if mode == 1 and not vibration_switch.value:
|
||||
print("Sparkle mode activate!")
|
||||
pixels.brightness = 1
|
||||
sparkle_color_index = (
|
||||
sparkle_color_index + 1) % len(sparkle_color_list)
|
||||
sparkle_color_index = (sparkle_color_index + 1) % len(sparkle_color_list)
|
||||
sparkle_code(sparkle_color_list[sparkle_color_index])
|
||||
if mode == 2 and not vibration_switch.value:
|
||||
print("Chase mode activate!")
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False)
|
|||
|
||||
def lerp(x, x0, x1, y0, y1):
|
||||
# Clamp x within x0 and x1 bounds.
|
||||
if (x > x1):
|
||||
if x > x1:
|
||||
x = x1
|
||||
|
||||
if (x < x0):
|
||||
if x < x0:
|
||||
x = x0
|
||||
|
||||
# Calculate linear interpolation of y value.
|
||||
return (y0 + (y1 - y0) * ((x - x0) / (x1 - x0)))
|
||||
return y0 + (y1 - y0) * ((x - x0) / (x1 - x0))
|
||||
|
||||
|
||||
# Set all pixels to the specified color.
|
||||
|
|
@ -67,7 +67,7 @@ def animate_gradient_fill(start_r, start_g, start_b, end_r, end_g, end_b, durati
|
|||
# Main animation loop.
|
||||
delta = time.monotonic() - start
|
||||
|
||||
while (delta < duration_ms):
|
||||
while delta < duration_ms:
|
||||
# Calculate how far along we are in the duration as a position 0...1.0
|
||||
pos = delta / duration_ms
|
||||
# Get the gradient color and fill all the pixels with it.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import neopixel
|
|||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except:
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
num_leds = 24 # 24 LED NeoPixel ring
|
||||
|
|
@ -60,7 +60,7 @@ while True: # Loop forever...
|
|||
last_vibration = t # Save last trigger time
|
||||
|
||||
# Stretch out frames if nothing has happened in a couple of seconds:
|
||||
if ((t - last_vibration) > cooldown_at):
|
||||
if (t - last_vibration) > cooldown_at:
|
||||
frame_len += 0.001 # Add 1 ms
|
||||
if frame_len > max_frame_len:
|
||||
frame_len = min_frame_len
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ def wheel(pos):
|
|||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0) or (pos > 255):
|
||||
return (0, 0, 0)
|
||||
if (pos < 85):
|
||||
if pos < 85:
|
||||
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||
elif (pos < 170):
|
||||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
|
|
@ -45,9 +45,9 @@ def rainbow_cycle(wait):
|
|||
|
||||
def rainbow(wait):
|
||||
for j in range(255):
|
||||
for i in range(len(pixels)):
|
||||
idx = int(i + j)
|
||||
pixels[i] = wheel(idx & 255)
|
||||
for index in range(len(pixels)):
|
||||
idx = int(index + j)
|
||||
pixels[index] = wheel(idx & 255)
|
||||
pixels.write()
|
||||
time.sleep(wait)
|
||||
|
||||
|
|
@ -72,26 +72,26 @@ def rainbow_hold(wait):
|
|||
|
||||
while True:
|
||||
|
||||
if (mode == 0): # rainbow hold
|
||||
if mode == 0: # rainbow hold
|
||||
rainbow_hold(0.02)
|
||||
time.sleep(.5)
|
||||
|
||||
elif (mode == 1): # rainbow cycle slow
|
||||
elif mode == 1: # rainbow cycle slow
|
||||
rainbow_cycle_slow(0.02)
|
||||
time.sleep(0.05)
|
||||
|
||||
elif (mode == 2): # rainbow cycle fast
|
||||
elif mode == 2: # rainbow cycle fast
|
||||
rainbow_cycle(0.005)
|
||||
time.sleep(0.050)
|
||||
|
||||
t = time.monotonic()
|
||||
|
||||
if ((t - prevtime) > 8): # Every 8 seconds...
|
||||
if (t - prevtime) > 8: # Every 8 seconds...
|
||||
mode += 1 # Next mode
|
||||
if (mode > 2): # End of modes?
|
||||
if mode > 2: # End of modes?
|
||||
mode = 0 # Start modes over
|
||||
|
||||
if (rgb_idx > 2): # reset R-->G-->B rotation
|
||||
if rgb_idx > 2: # reset R-->G-->B rotation
|
||||
rgb_idx = 0
|
||||
|
||||
color = rgb_colors[rgb_idx] # next color assignment
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ def wheel(pos):
|
|||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0) or (pos > 255):
|
||||
return (0, 0, 0)
|
||||
if (pos < 85):
|
||||
if pos < 85:
|
||||
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||
elif (pos < 170):
|
||||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
|
|
@ -47,6 +47,7 @@ def rainbow(wait):
|
|||
for i in range(len(strip)):
|
||||
idx = int(i + j)
|
||||
strip[i] = wheel(idx & 255)
|
||||
time.sleep(wait)
|
||||
|
||||
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -3,11 +3,6 @@ import time
|
|||
import board
|
||||
import neopixel
|
||||
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 64 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,6 @@ import time
|
|||
import board
|
||||
import neopixel
|
||||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 64 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ colors = [
|
|||
|
||||
|
||||
def flash_random(wait, howmany):
|
||||
for k in range(howmany):
|
||||
for _ in range(howmany):
|
||||
|
||||
c = random.randint(0, len(colors) - 1) # Choose random color index
|
||||
j = random.randint(0, numpix - 1) # Choose random pixel
|
||||
|
|
|
|||
|
|
@ -36,27 +36,27 @@ while True:
|
|||
gcolor = 0
|
||||
bcolor = 0
|
||||
|
||||
if (showcolor == 0): # Garden PINK
|
||||
if showcolor == 0: # Garden PINK
|
||||
rcolor = 242
|
||||
gcolor = 90
|
||||
bcolor = 255
|
||||
|
||||
elif (showcolor == 1): # Pixie GOLD
|
||||
elif showcolor == 1: # Pixie GOLD
|
||||
rcolor = 255
|
||||
gcolor = 222
|
||||
bcolor = 30
|
||||
|
||||
elif (showcolor == 2): # Alchemy BLUE
|
||||
elif showcolor == 2: # Alchemy BLUE
|
||||
rcolor = 50
|
||||
gcolor = 255
|
||||
bcolor = 255
|
||||
|
||||
elif (showcolor == 3): # Animal ORANGE
|
||||
elif showcolor == 3: # Animal ORANGE
|
||||
rcolor = 255
|
||||
gcolor = 100
|
||||
bcolor = 0
|
||||
|
||||
elif (showcolor == 4): # Tinker GREEN
|
||||
elif showcolor == 4: # Tinker GREEN
|
||||
rcolor = 0
|
||||
gcolor = 255
|
||||
bcolor = 40
|
||||
|
|
@ -84,17 +84,17 @@ while True:
|
|||
newstate = button.value
|
||||
|
||||
# Check if state changed from high to low (button press).
|
||||
if (newstate and not oldstate):
|
||||
if newstate and not oldstate:
|
||||
# Short delay to debounce button.
|
||||
time.sleep(0.020)
|
||||
|
||||
# Check if button is still low after debounce.
|
||||
newstate = button.value
|
||||
|
||||
if (newstate == False):
|
||||
if not newstate:
|
||||
showcolor += 1
|
||||
|
||||
if (showcolor > 4):
|
||||
if showcolor > 4:
|
||||
showcolor = 0
|
||||
|
||||
# Set the last button state to the old state.
|
||||
|
|
|
|||
|
|
@ -37,9 +37,8 @@ def wheel(pos):
|
|||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
def remap_range(value, leftMin, leftMax, rightMin, rightMax):
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ def wheel(pos):
|
|||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
pos -= 170
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
|
|
|
|||
Loading…
Reference in a new issue