@@ -90,6 +90,8 @@ class Touchscreen:
9090 readings for the X and Y coordinate planes, respectively.
9191 Defaults to :const:`((0, 65535), (0, 65535))`
9292 :param int,int size: The dimensions of the screen as (x, y).
93+ :param bool invert_pressure: Whether to invert the pressure values. Some touchscreens and
94+ drivers may need this to be changed to `False` in order to properly register touches.
9395
9496 """
9597
@@ -104,7 +106,8 @@ def __init__(
104106 samples : int = 4 ,
105107 z_threshold : int = 10000 ,
106108 calibration : Optional [Tuple [Tuple [int , int ], Tuple [int , int ]]] = None ,
107- size : Optional [Tuple [int , int ]] = None
109+ size : Optional [Tuple [int , int ]] = None ,
110+ invert_pressure : bool = True
108111 ) -> None :
109112
110113 self ._xm_pin = x1_pin
@@ -119,6 +122,7 @@ def __init__(
119122 self ._calib = calibration
120123 self ._size = size
121124 self ._zthresh = z_threshold
125+ self .invert_pressure = invert_pressure
122126
123127 @property
124128 def touch_point (
@@ -136,7 +140,10 @@ def touch_point(
136140 with AnalogIn (self ._yp_pin ) as y_p :
137141 z_2 = y_p .value
138142 # print(z_1, z_2)
139- z = 65535 - (z_2 - z_1 )
143+ if self .invert_pressure :
144+ z = 65535 - (z_2 - z_1 )
145+ else :
146+ z = z_2 + z_1
140147 if z > self ._zthresh :
141148 with DigitalInOut (self ._yp_pin ) as y_p :
142149 with DigitalInOut (self ._ym_pin ) as y_m :
0 commit comments