from machine import Pin, SPI
import ili9342c
import random
from machine import SoftI2C
import focaltouch
import time
def tftinit():
spi = SPI(2,baudrate=60000000,sck=Pin(18),mosi=Pin(23)) # SPI init
tft = ili9342c.ILI9342C(spi, cs=Pin(5, Pin.OUT), dc=Pin(15, Pin.OUT), rst=Pin(33, Pin.OUT),width=320, height=240,rotation=270)
return tft
class Rechteck(object):
def __init__(self, pos_x, pos_y, r_gr_x, r_gr_y, tft):
self.pos_x = pos_x
self.pos_y = pos_y
self.r_gr_x = r_gr_x
self.r_gr_y = r_gr_y
self.tft = tft
def draw(self):
print("draw")
self.tft.fill_rect(self.pos_x, self.pos_y, self.r_gr_x, self.r_gr_y, color=random.randint(0,65535))
def main():
print("Start")
print("tft initialisieren")
tft = tftinit()
tft.clear(ili9342c.WHITE)
# tft.fill_rect(0, 0, 100, 73, color=random.randint(0,65535)) #11111 11111 111111
# R1_1 = Rechteck(0,0,100,73,tft)
# print(R1_1)
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
touch = focaltouch.FocalTouch(i2c)
while True:
if touch.touched != 0:
print("")
print("x = ", touch.touches[0]['x'])
print("y = ", touch.touches[0]['y'])
tft.fill_rect(touch.touches[0]['y']-2, 240-touch.touches[0]['x']-2, 5, 5, color=random.randint(0,65535))
time.sleep(0.1)
print("Ende main")
if __name__ == "__main__":
main()