search working well progam for xpt2046

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
yellowpowerplay
Posts: 9
Joined: Fri Oct 22, 2021 6:04 pm

Re: search working well progam for xpt2046

Post by yellowpowerplay » Fri Oct 29, 2021 4:08 pm

Thank you Roberthh .Nice to have someone like you to help us .
The fully working program for other beginners like me. Switches an LED on off via touch

"""ILI9341/xpt2046 demo _ESP32 defkitV1"""
#connection on ESP32
#TFT-----------------Touch
# MISO = 19------= 12
# MOSI =23-------= 13
# clk =18---------- = 14
# CS = 5---------- = 15
# Rst = 33------- T-IRQ = NC

# led = 25

#--------------------------------------------------------------------------------------------------------------------------
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from xglcd_font import XglcdFont
import xpt2046_syn
led = Pin(25 , Pin.OUT)

spi = SPI(2, baudrate=40000000, sck=Pin(18), mosi=Pin(23))
display = Display(spi, dc=Pin(27), cs=Pin(5), rst=Pin(33))
print('Loading fonts...')
print('Loading espresso_dolce')

espresso_dolce = XglcdFont('font/EspressoDolse18x24.c',18 , 24)

print('Fonts loaded.')
def test():

display.fill_rectangle(50, 20, 150, 280, color565(0,255,255))
display.draw_text(80, 50, ' select ', espresso_dolce , color565(255,255,255))
display.draw_text(80, 150, ' LED_on ', espresso_dolce , color565(0,0,0),
background=color565(255, 0, 100))
display.draw_text(80, 200, ' LED_off ' ,espresso_dolce, color565(0, 0, 0),
background=color565(0, 0, 255))
test()

import machine
spi = machine.SPI(1, baudrate=1000000, miso=machine.Pin(12), mosi=machine.Pin(13), sck=machine.Pin(14))
ts_cs = machine.Pin(15, machine.Pin.OUT)

touch = xpt2046_syn.XPT2046(spi = spi, confidence=5, margin=50, delay=10, calibration=None)
ts_cs.value(0)

while True:
res = touch.get_touch(initial=False, wait=True, raw=False, timeout=300)
if res is not None:
x_value,y_value = res
else:
continue
if x_value > 170 and x_value < 300:
if y_value > 120 and y_value < 130:
led(1) #set led on

if x_value > 170 and x_value < 300:
if y_value > 70 and y_value < 90:
led(0) #set led off

print(str(x_value)) #print x_value on Shell
print(str(y_value)) #print y_value on Shell
Last edited by yellowpowerplay on Fri Oct 29, 2021 4:40 pm, edited 1 time in total.

yellowpowerplay
Posts: 9
Joined: Fri Oct 22, 2021 6:04 pm

Re: search working well progam for xpt2046

Post by yellowpowerplay » Fri Oct 29, 2021 5:28 pm

custom_resized_.jpg
custom_resized_.jpg (202.57 KiB) Viewed 870 times
Attachments
custom_resized_.jpg
custom_resized_.jpg (202.57 KiB) Viewed 870 times

Post Reply