Add auto_write=False, turn off DotStar, linting.
This commit is contained in:
parent
dbc544a37b
commit
c3efe11e06
1 changed files with 15 additions and 12 deletions
|
|
@ -5,30 +5,33 @@ import time
|
|||
|
||||
import board
|
||||
import neopixel
|
||||
import adafruit_dotstar
|
||||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
dot = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
|
||||
dot[0] = (0, 0, 0)
|
||||
|
||||
numpix = 16 # Number of NeoPixels (e.g. 16-pixel ring)
|
||||
pixpin = board.D0 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.3)
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.3, auto_write=False)
|
||||
|
||||
|
||||
def wheel(pos):
|
||||
# Input a value 0 to 255 to get a color value.
|
||||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0) or (pos > 255):
|
||||
return [0, 0, 0]
|
||||
elif pos < 85:
|
||||
return [int(pos * 3), int(255 - (pos * 3)), 0]
|
||||
elif pos < 170:
|
||||
if pos < 0 or pos > 255:
|
||||
return (0, 0, 0)
|
||||
if pos < 85:
|
||||
return (int(255 - pos*3), int(pos*3), 0)
|
||||
if 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)]
|
||||
return (0, int(255 - pos*3), int(pos*3))
|
||||
pos -= 170
|
||||
return (int(pos * 3), 0, int(255 - (pos*3)))
|
||||
|
||||
|
||||
mode = 0 # Current animation effect
|
||||
|
|
@ -45,14 +48,14 @@ while True: # Loop forever...
|
|||
# Set same pixel to "off" color now but DON'T refresh...
|
||||
# it stays on for now...bot this and the next random
|
||||
# pixel will be refreshed on the next pass.
|
||||
strip[i] = [0,0,0]
|
||||
strip[i] = [0, 0, 0]
|
||||
time.sleep(0.008) # 8 millisecond delay
|
||||
elif mode == 1: # Spinny wheel (4 LEDs on at a time)
|
||||
for i in range(numpix): # For each LED...
|
||||
if ((offset + i) & 7) < 2: # 2 pixels out of 8...
|
||||
strip[i] = color # are set to current color
|
||||
else:
|
||||
strip[i] = [0,0,0] # other pixels are off
|
||||
strip[i] = [0, 0, 0] # other pixels are off
|
||||
strip.show() # Refresh LED states
|
||||
time.sleep(0.04) # 40 millisecond delay
|
||||
offset += 1 # Shift animation by 1 pixel on next frame
|
||||
|
|
|
|||
Loading…
Reference in a new issue