Datasheet

CircuitPython Cap Touch
Every CircuitPython designed M0 board has capacitive touch capabilities. This means each board has at least one pin
that works as an input when you touch it! The capacitive touch is done
completely
in hardware, so no external
resistors, capacitors or ICs required. Which is really nice!
This example will show you how to use a capacitive touch pin on your board.
Copy and paste the code into code.py using your favorite editor, and save the file.
Create the Touch Input
First, we assign the variable touch_pad to a pin. The example uses A0, so we assign touch_pad = board.A0 . You can
choose any touch capable pin from the list below if you'd like to use a different pin. Then we create the touch object,
name it touch and attach it to touch_pad .
To use with Circuit Playground Express, comment out touch_pad = board.A0 and uncomment touch_pad = board.A1 .
Main Loop
Next, we create a loop that checks to see if the pin is touched. If it is, it prints to the serial console. Connect to the
serial console to see the printed results when you touch the pin!
No extra hardware is required, because you can touch the pin directly. However, you may want to attach alligator clips
or copper tape to metallic or conductive objects. Try metal flatware, fruit or other foods, liquids, aluminum foil, or other
items lying around your desk!
Capacitive touch is not supported on the M4 Express boards.
import time
import board
import touchio
touch_pad = board.A0 # Will not work for Circuit Playground Express!
# touch_pad = board.A1 # For Circuit Playground Express
touch = touchio.TouchIn(touch_pad)
while True:
if touch.value:
print("Touched!")
time.sleep(0.05)
Remember: To "comment out" a line, put a # and a space before it. To "uncomment" a line, remove the # +
space from the beginning of the line.
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-
circuitpython
Page 124 of 199