- MicroPython Cookbook
- Marwan Alsabbagh
- 97字
- 2025-04-04 14:22:37
How to do it...
Let's perform the following steps:
- First, run the following lines of code in the REPL. The value of cpx.button_a is False here because the button is not pressed:
>>> from adafruit_circuitplayground.express import cpx >>> cpx.button_a False
- Keep push button A pressed while you run the following code block. This will change the value to True:
>>> cpx.button_a True
- Then, add the following code to the main.py file and this will repeatedly print the state of push button A on execution:
from adafruit_circuitplayground.express import cpx import time while True: print(cpx.button_a) time.sleep(0.05)