0

Button in use in a Py program, not live
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Button in use in a Py program, not live

by HoustonGeek on Wed May 19, 2021 11:01 am

CPE - 3.13.0 BL, CPE Code 3.6.0

My code.py:
Code: Select all | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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

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

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

by adafruit_support_carter on Wed May 19, 2021 1:15 pm

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 | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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

adafruit_support_carter
 
Posts: 20679
Joined: Tue Nov 29, 2016 2:45 pm

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

by HoustonGeek on Wed May 19, 2021 1:34 pm

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

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

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

by adafruit_support_carter on Wed May 19, 2021 1:36 pm

Might want to think about deprecating the old posts.

Please link to this and we'll take a look.

adafruit_support_carter
 
Posts: 20679
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.