The Circuit Playground Express has two buttons. Button A is on the left and button B is on the right. We can use these buttons to update our board’s status when pressed.
We can access the statuses of the buttons using:
cpx.button_a
cpx.button_b
For example:
from adafruit_circuitplayground.express import cpx while True: if cpx.button_a: # code when Button A is pressed elif cpx.button_b: # code when Button B is pressed
Instructions
Inside the while
loop, we are going to add an if, else if, else statement:
If
cpx.button_a
is pressed, setcpx.pixels[2]
as red.Else if
cpx.button_b
is pressed, setcpx.pixels[7]
as green.Else, turn all the NeoPixels off.
Click the Download button to download the code.py file.
Drag and drop the downloaded file into the CIRCUITPY drive on your computer.
Press the button A a few times and press the button B a few times.