I'm having and issue with the coding part of the NeoPixel led. I copied the glasses tutorial circuit python - got it working for the most part but can't figure out why it's not bouncing back on the full strip.
I couldn't upload video so here is a gif : https://giphy.com/gifs/SPseOULLIijaFxY5V6
This is the code - it dies out before it gets back to the beginning. Not sure where I am going wrong.
*********************
Code: Select all
import time
import board
import neopixel
numpix = 60 # Number of NeoPixels
pixpin = board.D1 # NeoPixels pin. For Gemma M0 = D1, Trinket M0 = D4
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False)
pos = 0 # position
direction = 1 # direction of "eye"
while True:
strip[pos - 2] = ([240, 240, 240]) # Dark red
strip[pos - 1] = ([250, 250, 250]) # Medium red
strip[pos] = ([255, 255, 255]) # brightest
strip[pos + 1] = ([250, 250, 250]) # Medium red
if (pos + 2) < numpix:
# Dark red, do not exceed number of pixels
strip[pos + 2] = ([240, 240, 240])
strip.write()
time.sleep(0)
# Rather than being sneaky and erasing just the tail pixel,
# it's easier to erase it all and draw a new one next time.
for j in range(-2, 2):
strip[pos + j] = (0, 0, 0)
if (pos + 2) < numpix:
strip[pos + 2] = (0, 0, 0)
# Bounce off ends of strip
pos += direction
if pos < 0:
pos = 1
direction = -direction
elif pos >= (numpix - 1):
pos = numpix - 2
direction = -direction