Adafruit is open and shipping! Let's build back better, together!
0

pixels.fill not working?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

pixels.fill not working?

by Rcayot on Wed Nov 18, 2020 11:15 am

I am having trouble with a CP program. Between patterns of lighting LEDs in a strip, I want to clear all of the LEDs, or set them to black.

I keep getting a syntax error:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 76, in <module>
File "<stdin>", line 46, in up
File "neopixel.py", line 212, in fill
File "neopixel.py", line 172, in __setitem__
File "neopixel.py", line 155, in _set_item
TypeError: can't convert float to int

I know it is likely a simple error, but I have tried several combinations of how to do this, and I am still stuck.


Code: Select all | TOGGLE FULL SIZE
import board
import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy
import time
num_leds = 16
i = 0
pixels = neopixel.NeoPixel(board.A0, num_leds, brightness=1.0,
                           auto_write=False)
loopmillis = 0

patterndown = [0, .07, .13, .2, .27, .33, .4, .47, .53, .6, .67, .73, .8, .87, .93, 1.0]
patternup = [1.0, .93, .87, .8, .73, .67, .6, .53, .47, .4, .33, .27, .2, .13, .07, 0]
i = 0
index = 0
count = 0
black = fancy.CRGB(0.0, 0.0, 0.0)

# pixelscopy[] = pixels.copy[]
def up():
    initial = time.monotonic()
    index = 0
    count = 0
    while count <= len(pixels):
        now = time.monotonic()
        if now - initial > .01:
            if index == 0:
                temp = patternup[index]
            if index < 15:
                patternup[index] = patternup[index+1]
            if index == 15:
                patternup[index] = temp
            color = fancy.CHSV(0, 1.0,  patternup[index])
            levels = (.75, .8, .60)
            gammas = (2.9, 2.5, 2.4)
            color = fancy.gamma_adjust(color, brightness=levels, gamma_value=gammas)
            pixels[index] = color.pack()
            pixels.show()
            # print(count)
            #print(pattern[index], index)
            index = index + 1
            if index> 15:
                index = 0
                initial = now
                count = count + 1
            if count == len(pixels):
                pixels.fill(black)
                pixels.show()

def down():
    initial = time.monotonic()
    index = 15
    count = 0
   
    while count <= len(pixels):
        now = time.monotonic()
        if now - initial > .01:
            if index == 15:
                temp = patterndown[index]
            if index > 0:
                patterndown[index] = patterndown[index-1]
            if index == 0:
                patterndown[index] = temp
            color = fancy.CHSV(0, 1.0,  patterndown[index])
            levels = (.75, .8, .60)
            gammas = (2.9, 2.5, 2.4)
            color = fancy.gamma_adjust(color, brightness=levels, gamma_value=gammas)
            pixels[index] = color.pack()
            pixels.show()
            index = index - 1
            if index < 0:
                index = 15
                initial = now
                count = count + 1

while True:
    up()
    down()

Rcayot
 
Posts: 79
Joined: Sat Feb 08, 2020 6:48 pm

Re: pixels.fill not working?

by dastels on Wed Nov 18, 2020 1:00 pm

Try:
Code: Select all | TOGGLE FULL SIZE
pixels.fill(0x000000)

or
Code: Select all | TOGGLE FULL SIZE
pixels.fill((0,0,0))


Dave

dastels
 
Posts: 4230
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.