-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTouch_test.py
46 lines (39 loc) · 1.11 KB
/
Touch_test.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
import tft_config
import s3lcd
import vga1_8x8 as font
from machine import SPI, Pin
from xpt2046 import Touch
from time import sleep
spi = SPI(1, baudrate=1000000)
spi.init(sck=Pin(01), mosi=Pin(03), miso=Pin(04))
print('ok SPI')
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)
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:
x, y = xpt.get_touch()
tft.rect(x, y, 2, 2, s3lcd.RED)
tft.show()
if xpt.is_touched():
print(f'x={x}, y={y}')
sleep(0.1)
finally:
tft.deinit()