adafruit_touchscreen
¶
CircuitPython library for 4-wire resistive touchscreens
Author(s): ladyada
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class adafruit_touchscreen.Touchscreen(x1_pin: Pin, x2_pin: Pin, y1_pin: Pin, y2_pin: Pin, *, x_resistance: int | None = None, samples: int = 4, z_threshold: int = 10000, calibration: Tuple[Tuple[int, int], Tuple[int, int]] | None = None, size: Tuple[int, int] | None = None, invert_pressure: bool = True)¶
A driver for common and inexpensive resistive touchscreens. Analog input capable pins are required to read the intrinsic potentiometers
Create the Touchscreen object. At a minimum you need the 4 pins that will connect to the 4 contacts on a screen. X and Y are just our names, you can rotate and flip the data if you like. All pins must be capable of becoming DigitalInOut pins.
y2_pin
,x1_pin
andx2_pin
must also be capable of becoming AnalogIn pins. If you know the resistance across the x1 and x2 pins when not touched, pass that in as ‘x_resistance’.calibration
is a tuple of two tuples, the default is ((0, 65535), (0, 65535)). The numbers are the min/max readings for the X and Y coordinate planes, respectively. To figure these out, pass in no calibration value or size value and read the raw minimum and maximum values out while touching the panel.size
is a tuple that gives the X and Y pixel size of the underlying screen. If passed in, we will automatically scale/rotate so touches correspond to the graphical coordinate system.- Parameters:
x1_pin (Pin) – Data pin for Left side of the screen. Must also be capable of becoming AnalogIn pins.
x2_pin (Pin) – Data pin for Right side of the screen. Must also be capable of becoming AnalogIn pins.
y1_pin (Pin) – Data pin for Bottom side of the screen.
y2_pin (Pin) – Data pin for Top side of the screen. Must also be capable of becoming AnalogIn pins.
x_resistance (int) – If you know the resistance across the x1 and x2 pins when not touched, pass that in as
x_resistance
samples (int) – change by adjusting
samples
arg. Defaults to4
z_threshold (int) – We can also detect the ‘z’ threshold, how much its pressed. We don’t register a touch unless its higher than
z_threshold
calibration ((int,int),(int,int)) – A tuple of two tuples The numbers are the min/max readings for the X and Y coordinate planes, respectively. Defaults to
((0, 65535), (0, 65535))
invert_pressure (bool) – Whether to invert the pressure values. Some touchscreens and drivers may need this to be changed to
False
in order to properly register touches.