TouchIn – Read the state of a capacitive touch sensor

Usage:

import touchio
from board import *

touch = touchio.TouchIn(A1)
while True:
    if touch.value:
        print("touched!")
class touchio.TouchIn(pin)

Use the TouchIn on the given pin.

Parameters:pin (Pin) – the pin to read from
deinit()

Deinitialises the TouchIn and releases any hardware resources for reuse.

__enter__()

No-op used by Context Managers.

__exit__()

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

value

Whether the touch pad is being touched or not. (read-only)

True when raw_value > threshold.

raw_value

The raw touch measurement as an int. (read-only)

threshold

Minimum raw_value needed to detect a touch (and for value to be True).

When the TouchIn object is created, an initial raw_value is read from the pin, and then threshold is set to be 100 + that value.

You can adjust threshold to make the pin more or less sensitive.