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
5
6import adafruit_touchscreen
7
8# These pins are used as both analog and digital! XL, XR and YU must be analog
9# and digital capable. YD just need to be digital
10ts = adafruit_touchscreen.Touchscreen(
11 board.TOUCH_XL,
12 board.TOUCH_XR,
13 board.TOUCH_YD,
14 board.TOUCH_YU,
15 calibration=((5200, 59000), (5800, 57000)),
16 size=(320, 240),
17)
18
19while True:
20 p = ts.touch_point
21 if p:
22 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
5
6import adafruit_touchscreen
7
8# Allign the touchscreen so that the top left corner reads as x=0, y=0
9# Change rotation variable to display setup code for the opropriate touchscreen orientation.
10
11rotation = 270
12
13if rotation == 0:
14 # -------Rotate 0:
15 ts = adafruit_touchscreen.Touchscreen(
16 board.TOUCH_XL,
17 board.TOUCH_XR,
18 board.TOUCH_YD,
19 board.TOUCH_YU,
20 calibration=((5200, 59000), (5800, 57000)),
21 size=(320, 240),
22 )
23
24if rotation == 90:
25 # -------Rotate 90:
26 ts = adafruit_touchscreen.Touchscreen(
27 board.TOUCH_YU,
28 board.TOUCH_YD,
29 board.TOUCH_XL,
30 board.TOUCH_XR,
31 calibration=((5200, 59000), (5800, 57000)),
32 size=(240, 320),
33 )
34
35if rotation == 180:
36 # ------Rotate 180:
37 ts = adafruit_touchscreen.Touchscreen(
38 board.TOUCH_XR,
39 board.TOUCH_XL,
40 board.TOUCH_YU,
41 board.TOUCH_YD,
42 calibration=((5200, 59000), (5800, 57000)),
43 size=(320, 240),
44 )
45
46if rotation == 270:
47 # ------Rotate 270:
48 ts = adafruit_touchscreen.Touchscreen(
49 board.TOUCH_YD,
50 board.TOUCH_YU,
51 board.TOUCH_XR,
52 board.TOUCH_XL,
53 calibration=((5200, 59000), (5800, 57000)),
54 size=(240, 320),
55 )
56
57while True:
58 p = ts.touch_point
59 if p:
60 print(p)