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

How to do it...

Let's perform the following steps:

  1. Run the following lines of code in the REPL. The value of cpx.touch_A1 is False because touchpad A1 is not being touched:
>>> from adafruit_circuitplayground.express import cpx
>>> cpx.touch_A1
False
  1. Keep your finger touching touchpad A1 while you run the following code block:
>>> cpx.touch_A1
True
  1. The following code should be added to the main.py file. This will print a message every time you press touchpad A1:
from adafruit_circuitplayground.express import cpx
import time

while True:
    if cpx.touch_A1:
        print('detected touch')
    time.sleep(0.05)