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



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.


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.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?