The Circuit Playground Express has two buttons. Button A is on the left and button B is on the right. These buttons can be used as inputs, which means you can use them to tell your board to do something when you press them.
In this example, we'll use the buttons of the CPX to change the colors of the NeoPixels. Button A will turn them red, and B will turn them blue.
|
|
|
|
Download the file and drag to the CPX.
Try it out!
When button A is pressed, NeoPixels should turn red.
When button B is pressed they should turn blue!
Here are the code files if you want to upload directly to EduBlocks or the CPX.
np = None button_a = None button_b = None from digitalio import * import board import neopixel np = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness = 0.2) np.fill((0,0,0)) np.show() button_a = DigitalInOut(board.BUTTON_A) button_a.direction = Direction.INPUT button_a.pull = Pull.DOWN button_b = DigitalInOut(board.BUTTON_B) button_b.direction = Direction.INPUT button_b.pull = Pull.DOWN while True: if button_a.value: np.fill((255,0,0)) np.show() elif button_b.value: np.fill((0,0,255)) np.show()