/ examples / touchscreen_orientation.py
touchscreen_orientation.py
 1  import board
 2  import adafruit_touchscreen
 3  
 4  # Allign the touchscreen so that the top left corner reads as x=0, y=0
 5  # Change rotation variable to display setup code for the opropriate touchscreen orientation.
 6  
 7  rotation = 270
 8  
 9  if rotation == 0:
10      # -------Rotate 0:
11      ts = adafruit_touchscreen.Touchscreen(
12          board.TOUCH_XL,
13          board.TOUCH_XR,
14          board.TOUCH_YD,
15          board.TOUCH_YU,
16          calibration=((5200, 59000), (5800, 57000)),
17          size=(320, 240),
18      )
19  
20  if rotation == 90:
21      # -------Rotate 90:
22      ts = adafruit_touchscreen.Touchscreen(
23          board.TOUCH_YU,
24          board.TOUCH_YD,
25          board.TOUCH_XL,
26          board.TOUCH_XR,
27          calibration=((5200, 59000), (5800, 57000)),
28          size=(240, 320),
29      )
30  
31  if rotation == 180:
32      # ------Rotate 180:
33      ts = adafruit_touchscreen.Touchscreen(
34          board.TOUCH_XR,
35          board.TOUCH_XL,
36          board.TOUCH_YU,
37          board.TOUCH_YD,
38          calibration=((5200, 59000), (5800, 57000)),
39          size=(320, 240),
40      )
41  
42  if rotation == 270:
43      # ------Rotate 270:
44      ts = adafruit_touchscreen.Touchscreen(
45          board.TOUCH_YD,
46          board.TOUCH_YU,
47          board.TOUCH_XR,
48          board.TOUCH_XL,
49          calibration=((5200, 59000), (5800, 57000)),
50          size=(240, 320),
51      )
52  
53  while True:
54      p = ts.touch_point
55      if p:
56          print(p)