touchio – Touch related IO
touchio module contains classes to provide access to touch IO typically
accelerated by hardware on the onboard microcontroller.
All classes change hardware state and should be deinitialized when they
are no longer needed if the program continues after use. To do so, either
deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
For more information about working with the
touchio module in CircuitPython,
see this Learn guide page.
import touchio from board import * touch_pin = touchio.TouchIn(D6) print(touch_pin.value)
This example will initialize the the device, and print the
Available on these boards
- class touchio.TouchIn(pin: microcontroller.Pin)
Read the state of a capacitive touch sensor
import touchio from board import * touch = touchio.TouchIn(A1) while True: if touch.value: print("touched!")
Use the TouchIn on the given pin.
pin (Pin) – the pin to read from
- value: bool
Whether the touch pad is being touched or not. (read-only)
- threshold: int | None
raw_valueneeded to detect a touch (and for
When the TouchIn object is created, an initial
raw_valueis read from the pin, and then
thresholdis set to be 100 + that value.
You can adjust
thresholdto make the pin more or less sensitive:
import board import touchio touch = touchio.TouchIn(board.A1) touch.threshold = 7300
- __exit__() None
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.