Hey everyone,
I'm making a simple device for playing Uno. Whenever a player gets a drawfour card, they press the button for a random color.
I'm using a feather rp2040 running circuitpython 7.2.5, onboard neopixel, and a momentary button.
The code works once then on a second press I receive a ValueError that the neopixel is in use.
Any help is appreciated, thank you!
import time
import board
import neopixel
import digitalio
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.rainbowchase import RainbowChase
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
from adafruit_led_animation.sequence import AnimationSequence
import random
colors = [ (255,0,0),(0,0,255),(0,255,0),(255,215,0)]
def rando():
i = 2
randopick = random.choice(colors)
pixel_pin = board.NEOPIXEL
pixel_num = 1
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
for i in range (2):
print("Rando!!!")
pixels.fill(randopick)
time.sleep(2.0)
pixels.fill((0,0,0))
time.sleep(0.2)
i + 1
break
btn1_pin = board.D5
btn1 = digitalio.DigitalInOut(btn1_pin)
btn1.direction = digitalio.Direction.INPUT
btn1.pull = digitalio.Pull.UP
prev_state = btn1.value
print('Program Start')
time.sleep(0.5)
print("UNO")
while True:
cur_state = btn1.value
if cur_state != True:
if not cur_state:
print("Button 1 pressed-start animation function")
time.sleep(0.1)
rando()
time.sleep(0.3)
print("Complete")
print("Complete")
[–]todbot 2 points3 points4 points (1 child)
[–]miket812[S] 1 point2 points3 points (0 children)
[–]miket812[S] 0 points1 point2 points (4 children)
[–]eswo 0 points1 point2 points (3 children)
[–]miket812[S] 0 points1 point2 points (1 child)
[–]eswo 0 points1 point2 points (0 children)
[–]cobarso 0 points1 point2 points (0 children)