Button in use in a Py program, not live

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
HoustonGeek
 
Posts: 3
Joined: Wed Sep 19, 2018 3:17 pm

Button in use in a Py program, not live

Post by HoustonGeek »

CPE - 3.13.0 BL, CPE Code 3.6.0

My code.py:

Code: Select all

2 import board
3 import digitalio
4 from adafruit_circuitplayground.express import cpx
5 #comment
6 button_a = digitalio.DigitalInOut(board.BUTTON_A)
7 button_a.direction = digitalio.Direction.INPUT
8 button_a.pull = digitalio.Pull.DOWN
and get a

Code: Select all

code.py ouput:
Traceback (most recent call last):
  File "code.py", line 6, in <module>
ValueError: BUTTON_A in use
however, when I issue those commands in the interpreter, it runs fine.

Reflash the CPE code? Not sure what the issue is

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Button in use in a Py program, not live

Post by adafruit_support_carter »

It should do the same thing either way. The CPX library sets up the digital input for you. So when you import it here:

Code: Select all

from adafruit_circuitplayground.express import cpx
BUTTON_A gets used. Here's the actual code that does that from the CPX library:
https://github.com/adafruit/Adafruit_Ci ... ase.py#L61

So you don't need to do any of this:

Code: Select all

6 button_a = digitalio.DigitalInOut(board.BUTTON_A)
7 button_a.direction = digitalio.Direction.INPUT
8 button_a.pull = digitalio.Pull.DOWN
Instead, access the button via the imported cpx object. Ex:
https://github.com/adafruit/Adafruit_Ci ... utton_a.py

User avatar
HoustonGeek
 
Posts: 3
Joined: Wed Sep 19, 2018 3:17 pm

Re: Button in use in a Py program, not live

Post by HoustonGeek »

Got it - I see newer projects with the correct code. Might want to think about deprecating the old posts.

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Button in use in a Py program, not live

Post by adafruit_support_carter »

Might want to think about deprecating the old posts.
Please link to this and we'll take a look.

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

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”