Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.
0

Trouble importing neopixel and and cpx libraries
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trouble importing neopixel and and cpx libraries

by MillenniumThalken on Sun Mar 15, 2020 5:07 pm

I am using the CPX and CircuitPython, trying to play some WAV files and LEDs on a button push. Currently I have two buttons and a STEMMA speaker connected to the CPX, I want to trigger one of the on board LED's when I push the button to play a WAV file.

if I import just the circuit playground express library I can play the WAV files:
Code: Select all | TOGGLE FULL SIZE
from adafruit_circuitplayground.express import cpx


if I import just the neopixel library I can get the lights working
Code: Select all | TOGGLE FULL SIZE
import neopixel


but if I do them together I get the following error:
Code: Select all | TOGGLE FULL SIZE
File "code.py", line 12, in <module>
           file "neopixel.py", line 91, in __init__
           ValueError: NEOPIXEL in use


here is the rest of my code:
Code: Select all | TOGGLE FULL SIZE
# Circuit Playground NeoPixel
# this is an exampleof using two buttons to fire the on board
from adafruit_circuitplayground.express import cpx
import time
import random
import board
import neopixel
import audioio
from digitalio import DigitalInOut, Direction, Pull
 

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.4, auto_write=False)

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
OFF = (0, 0, 0)


button_1 = DigitalInOut(board.A4)
button_1.direction = Direction.INPUT
button_1.pull = Pull.UP

button_2 = DigitalInOut(board.A2)
button_2.direction = Direction.INPUT
button_2.pull = Pull.UP

# pixels[1] = RED
# pixels.show()
 
while True:
    if not button_1.value:
        randNum = random.randint(0,2)
        if randNum == 2:
            cpx.play_file("blaster1.wav")
        elif randNum == 1:
            cpx.play_file("blaster2.wav")
        elif randNum == 0:
            cpx.play_file("blaster3.wav")
        print(randNum)
        # pixels.show()
    if not button_2.value:
        cpx.play_file("prep.wav")



MillenniumThalken
 
Posts: 16
Joined: Mon Oct 28, 2019 2:07 pm

Re: Trouble importing neopixel and and cpx libraries

by adafruit_support_mike on Mon Mar 16, 2020 1:05 am

[moved to the CircuitPython forum]

adafruit_support_mike
 
Posts: 61014
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trouble importing neopixel and and cpx libraries

by tannewt on Mon Mar 16, 2020 12:28 pm

Hi MillenniumThalken, the Circuit Playground library instantiates the neopixels for you already. They are available as `cpx.pixels`. No need to `import neopixel` yourself.

tannewt
 
Posts: 1536
Joined: Thu Oct 06, 2016 8:48 pm

Re: Trouble importing neopixel and and cpx libraries

by MillenniumThalken on Tue Mar 17, 2020 8:44 pm

That was the trick! Thanks I got it working.

MillenniumThalken
 
Posts: 16
Joined: Mon Oct 28, 2019 2:07 pm

Please be positive and constructive with your questions and comments.