Simple test

Ensure your device works with this simple test.

examples/touchscreen_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import adafruit_touchscreen
 6
 7# These pins are used as both analog and digital! XL, XR and YU must be analog
 8# and digital capable. YD just need to be digital
 9ts = adafruit_touchscreen.Touchscreen(
10    board.TOUCH_XL,
11    board.TOUCH_XR,
12    board.TOUCH_YD,
13    board.TOUCH_YU,
14    calibration=((5200, 59000), (5800, 57000)),
15    size=(320, 240),
16)
17
18while True:
19    p = ts.touch_point
20    if p:
21        print(p)

Orientation Example

Example showing how to setup the different display orientations

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