pin is touched.
"""
import time
import board
import touchio
touch = touchio.TouchIn(board.A4)
while True:
if touch.value:
print("Pin touched!")
time.sleep(0.1)
Now touch the pin indicated in the diagram above. You'll see Pin touched! printed
to the serial console!
First you import three modules: time , board and touchio . This makes these
modules available for use in your code. All three are built-in to CircuitPython, so you
don't find any library files in the Project Bundle.
Next, you create the touchio.TouchIn() object, and provide it the pin name using
the board module. You save that to the touch variable.
Inside the loop, you check to see if the pin is touched. If so, you print to the serial
console. Finally, you include a time.sleep() to slow it down a bit so the output is
readable.
That's all there is to reading touch on a single pin using touchio in CircuitPython!
Multiple Capacitive Touch Pins
The next example shows you how to read touches on multiple pins in a single
program.
©Adafruit Industries Page 172 of 263