Learn
Circuit Playground: Part 1
Button A & Button B

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.

Buttons

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

1.

Inside the while loop, we are going to add an if, else if, else statement:

  • If cpx.button_a is pressed, set cpx.pixels[2] as red.

  • Else if cpx.button_b is pressed, set cpx.pixels[7] as green.

  • Else, turn all the NeoPixels off.

2.

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.

Folder Icon

Sign up to start coding

Already have an account?