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