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, x2_pin, y1_pin, y2_pin, *, x_resistance=None, samples=4, z_threshold=10000, calibration=None, size=None)¶ 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 and read the raw 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))
- size (int,int) – The dimensions of the screen as (x, y).
-
touch_point
¶ A tuple that represents the x, y and z (touch pressure) coordinates of a touch. Or, None if no touch is detected