Help with NeoPixel led coding

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
billyjitsu
 
Posts: 8
Joined: Tue Oct 05, 2021 2:31 pm

Help with NeoPixel led coding

Post by billyjitsu »

HI All,
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

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Help with NeoPixel led coding

Post by dastels »

What do you mean by "dies out"?

Dave

User avatar
billyjitsu
 
Posts: 8
Joined: Tue Oct 05, 2021 2:31 pm

Re: Help with NeoPixel led coding

Post by billyjitsu »

dastels wrote:What do you mean by "dies out"?

Dave
It starts over before the sequence is finished:
https://giphy.com/gifs/SPseOULLIijaFxY5V6 here is a gif of the issue. goes to the end and starts to come back but then it starts the sequence over before completion

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Help with NeoPixel led coding

Post by dastels »

What are you powering the strip with?

Lighting 5 pixels at almost full brightness white will draw close to 300mA which, if you are powering from the board, might be causing a voltage dip that resets the board. To (dis)prove that hypothesis, add a println("anything") before the while True loop. If that gets printed once, that's not the problem. But if it gets printed repeatedly then that's what's happening. You can try using a simpler color like red (255, 0, 0). That will lower the current requirement to closer to 100mA.

Dave

User avatar
billyjitsu
 
Posts: 8
Joined: Tue Oct 05, 2021 2:31 pm

Re: Help with NeoPixel led coding

Post by billyjitsu »

dastels wrote:What are you powering the strip with?

Lighting 5 pixels at almost full brightness white will draw close to 300mA which, if you are powering from the board, might be causing a voltage dip that resets the board. To (dis)prove that hypothesis, add a println("anything") before the while True loop. If that gets printed once, that's not the problem. But if it gets printed repeatedly then that's what's happening. You can try using a simpler color like red (255, 0, 0). That will lower the current requirement to closer to 100mA.

Dave
currently plugged in via USB from computer, no external power source (battery as of yet). I'm using the circuit python .. so just using the MU to edit and literally drag and drop. For the print, how would I see such a thing. Is there a guide?

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”