MicroPython Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Let's perform the following steps:

  1. 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
  1. Keep push button A pressed while you run the following code block. This will change the value to True:
>>> cpx.button_a
True
  1. 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)