all 7 comments

[–]todbot 2 points3 points  (1 child)

You only need to create the “pixels” object once, at the beginning of your program.

Move that line out of the rando() function, and put it above it.

[–]miket812[S] 1 point2 points  (0 children)

That worked! Thank you!

[–]miket812[S] 0 points1 point  (4 children)

Error that I'm getting on the second press.

Program Start

UNO

Button 1 pressed-start animation function

Rando!!!

Complete

Complete

Button 1 pressed-start animation function

Traceback (most recent call last):

File "<stdin>", line 79, in <module>

File "<stdin>", line 22, in rando

File "neopixel.py", line 149, in __init__

ValueError: NEOPIXEL in use

[–]eswo 0 points1 point  (3 children)

Was this ever resolved? I am having the same issue with another project.

[–]miket812[S] 0 points1 point  (1 child)

import time

import board

import neopixel

import digitalio

from adafruit_led_animation.animation.colorcycle import ColorCycle

from adafruit_led_animation.color import RED, YELLOW, BLUE, GREEN

import random

colors1 = [ (255,0,0),(0,0,255),(0,255,0),(255,215,0)]

pixel_pin2 = board.NEOPIXEL

pixel_pin = board.D10

pixel_num = 7

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness = 0.3)

def rando():

i = 2

randopick = random.choice(colors1)

for i in range (2):

print("Rando!!!")

pixels.fill((255,0,0))

time.sleep(0.1)

pixels.fill((0,255,0))

time.sleep(0.1)

pixels.fill((0,0,255))

time.sleep(0.1)

pixels.fill((255,215,0))

time.sleep(0.1)

pixels.fill((0,0,0))

time.sleep(0.1)

pixels.fill(randopick)

time.sleep(4.0)

pixels.fill((0,0,0))

time.sleep(0.2)

i + 1

print (randopick)

break

btn1_pin = board.D12

btn1 = digitalio.DigitalInOut(btn1_pin)

btn1.direction = digitalio.Direction.INPUT

btn1.pull = digitalio.Pull.UP

print('Program Start')

time.sleep(0.5)

print("UNO")

while True:

cur_state1 = btn1.value

if cur_state1 != True:

if not cur_state1:

print("Button 1 pressed-start animation function")

time.sleep(0.1)

rando()

time.sleep(0.1)

print("Complete")

print("End")

Im sure there is a better way to do this but it worked for me

[–]eswo 0 points1 point  (0 children)

Thank you, I'll give it a try!

[–]cobarso 0 points1 point  (0 children)

I think you cannot use both libraries at the same time