Fixes Flake 8 Issues Animated NeoPixel Glow Fur Scarf

This commit is contained in:
Aaron Dershem 2018-05-14 16:57:38 -04:00
parent 1cde6aa889
commit ef9cc08b5a

View file

@ -3,15 +3,15 @@ import board
import neopixel import neopixel
from digitalio import DigitalInOut, Direction, Pull from digitalio import DigitalInOut, Direction, Pull
led_pin = board.D1 # which pin your pixels are connected to led_pin = board.D1 # which pin your pixels are connected to
num_leds = 78 # how many LEDs you have num_leds = 78 # how many LEDs you have
brightness = 1.0 # 0-1, higher number is brighter brightness = 1.0 # 0-1, higher number is brighter
saturation = 255 # 0-255, 0 is pure white, 255 is fully saturated color saturation = 255 # 0-255, 0 is pure white, 255 is fully saturated color
steps = 0.01 # how wide the bands of color are. steps = 0.01 # how wide the bands of color are.
offset = 0 # cummulative steps offset = 0 # cummulative steps
fadeup = True # start with fading up - increase steps until offset reaches 1 fadeup = True # start with fading up - increase steps until offset reaches 1
index = 8 # midway color selection index = 8 # midway color selection
blend = True # color blending between palette indices blend = True # color blending between palette indices
# initialize list with all pixels off # initialize list with all pixels off
palette = [0] * num_leds palette = [0] * num_leds
@ -68,9 +68,9 @@ def wheel(pos):
# The colours are a transition r - g - b - back to r. # The colours are a transition r - g - b - back to r.
if (pos < 0) or (pos > 255): if (pos < 0) or (pos > 255):
return (0, 0, 0) return (0, 0, 0)
if (pos < 85): if pos < 85:
return (int(pos * 3), int(255 - (pos * 3)), 0) return (int(pos * 3), int(255 - (pos*3)), 0)
elif (pos < 170): elif pos < 170:
pos -= 85 pos -= 85
return (int(255 - pos * 3), 0, int(pos * 3)) return (int(255 - pos * 3), 0, int(pos * 3))
else: else:
@ -91,11 +91,10 @@ def remapRange(value, leftMin, leftMax, rightMin, rightMax):
def shortkeypress(color_palette): def shortkeypress(color_palette):
color_palette += 1 color_palette += 1
if (color_palette > 6): if color_palette > 6:
color_palette = 1 color_palette = 1
return (color_palette) return color_palette
while True: while True:
@ -103,38 +102,38 @@ while True:
currkeystate = button.value currkeystate = button.value
# button press, move to next pattern # button press, move to next pattern
if ((prevkeystate == False) and (currkeystate == True)): if (prevkeystate != True) and currkeystate:
ledmode = shortkeypress(ledmode) ledmode = shortkeypress(ledmode)
# save button press state # save button press state
prevkeystate = currkeystate prevkeystate = currkeystate
# Fire Colors [ HEAT ] # Fire Colors [ HEAT ]
if (ledmode == 1): if ledmode == 1:
palette = heat_colors palette = heat_colors
# Forest # Forest
elif (ledmode == 2): elif ledmode == 2:
palette = forest palette = forest
# Ocean # Ocean
elif (ledmode == 3): elif ledmode == 3:
palette = ocean palette = ocean
# Purple Lovers # Purple Lovers
elif (ledmode == 4): elif ledmode == 4:
palette = purple palette = purple
# All the colors! # All the colors!
elif (ledmode == 5): elif ledmode == 5:
palette = rainbow palette = rainbow
# Rainbow stripes # Rainbow stripes
elif (ledmode == 6): elif ledmode == 6:
palette = rainbow_stripe palette = rainbow_stripe
# All the colors except the greens, washed out # All the colors except the greens, washed out
elif (ledmode == 7): elif ledmode == 7:
palette = washed_out palette = washed_out
for i in range(num_leds): for i in range(num_leds):
@ -143,11 +142,11 @@ while True:
strip[i] = color.pack() strip[i] = color.pack()
strip.show() strip.show()
if (fadeup): if fadeup:
offset += steps offset += steps
if (offset >= 1): if offset >= 1:
fadeup = False fadeup = False
else: else:
offset -= steps offset -= steps
if (offset <= 0): if offset <= 0:
fadeup = True fadeup = True