-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTouch_test_interrupt.py
48 lines (40 loc) · 1.1 KB
/
Touch_test_interrupt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tft_config
import s3lcd
import vga1_8x8 as font
from machine import SPI, Pin
from xpt2046 import Touch
from time import sleep
t_x,t_y = 0,0
def int_handler(x,y):
global t_x,t_y
t_x = x
t_y = y
spi = SPI(1, baudrate=1000000)
spi.init(sck=Pin(01), mosi=Pin(03), miso=Pin(04))
cs = Pin(2, mode=Pin.OUT, value=1)
int_pin = Pin(9)
try:
tft = tft_config.config(tft_config.WIDE)
tft.init()
tft.clear(s3lcd.BLACK)
width = tft.height()
height = tft.width()
print(f'width= {tft.width()}, height= {tft.height()}')
xmin = 150
xmax = 1830
ymin = 150
ymax = 1830
orientation = 1
xpt = Touch(spi, cs=cs, int_pin=int_pin, int_handler=int_handler)
xpt.calibrate(xmin, xmax, ymin, ymax, width, height, orientation)
tft.fill(s3lcd.WHITE)
tft.rotation(orientation)
message = 'Click on the display'
tft.text(font, message, 25, 25, s3lcd.BLACK, s3lcd.WHITE)
tft.show()
while True:
if xpt.is_touched():
print(t_x,t_y)
sleep(0.05)
finally:
tft.deinit()