Datasheet
You can open up the serial console to see the touches detected and printed out.
Creating an capacitive touch input
Pads A1 - A7 can be used as capacitive TouchIn devices:
touch1 = touchio.TouchIn(board.A1)
touch2 = touchio.TouchIn(board.A2)
touch3 = touchio.TouchIn(board.A3)
touch4 = touchio.TouchIn(board.A4)
touch5 = touchio.TouchIn(board.A5)
touch6 = touchio.TouchIn(board.A6)
touch7 = touchio.TouchIn(board.A7)
Creates seven objects, one connected to each of the cap touch pads.
Main Loop
The main loop checks each sensor one after the other, to determine if it has been touched. If touch1.value returns True,
that means that that pad, A1 , detected a touch. For each pad, if it has been touched, a message will print.
A small sleep delay is added at the end so the loop doesn't run
too
fast. You may want to change the delay from 0.1
# CircuitPlaygroundExpress_CapTouch
import time
import board
import touchio
touch1 = touchio.TouchIn(board.A1)
touch2 = touchio.TouchIn(board.A2)
touch3 = touchio.TouchIn(board.A3)
touch4 = touchio.TouchIn(board.A4)
touch5 = touchio.TouchIn(board.A5)
touch6 = touchio.TouchIn(board.A6)
touch7 = touchio.TouchIn(board.A7)
while True:
if touch1.value:
print("A1 touched!")
if touch2.value:
print("A2 touched!")
if touch3.value:
print("A3 touched!")
if touch4.value:
print("A4 touched!")
if touch5.value:
print("A5 touched!")
if touch6.value:
print("A6 touched!")
if touch7.value:
print("A7 touched!")
time.sleep(0.01)
© Adafruit Industries https://learn.adafruit.com/adafruit-circuit-playground-express Page 121 of 211










