def checkTouch(): global x, y x = 0 y = 0 try: ts.init(i2c, ts.FT62XX) except: print('faile to init touchpad') showInfo("touchpad init failed", False) return else: showInfo("touchpad init done", True) print('pass to init touchpad') time.sleep(2) lcd.clear() img = image.Image() status_last = ts.STATUS_IDLE x_last = 0 y_last = 0 draw = False while button.value(): (status, x, y) = ts.read() if draw: img.draw_line((x_last, y_last, x, y)) if status_last != status: if (status == ts.STATUS_PRESS or status == ts.STATUS_MOVE): draw = True else: draw = False status_last = status img.draw_string(0, 0, "Touch me", lcd.GREEN, scale=2) lcd.display(img) x_last = x y_last = y del img ts.__del__()
HW_MPU6050 = False print('HAL MPU6050 FAILED') while True: if button.value()==0: while button.value()==0: pass lcd_rotation += 1 lcd_rotation %= 4 lcd.rotation(lcd_rotation) status = 0 x=0 y=0 if HW_TOUCH: (status, x, y) = ts.read() if (status == ts.STATUS_PRESS or status == ts.STATUS_MOVE): if lcd_rotation == 0: widht,height = lcd.width(),lcd.height() x,y = y,x x = lcd.width() - x elif lcd_rotation == 1: widht,height = lcd.width(),lcd.height() elif lcd_rotation == 2: widht,height = lcd.width(),lcd.height() x,y = y,x y = lcd.height() - y elif lcd_rotation == 3:
import machine import touchscreen as ts import time sda_pin = machine.Pin(23) scl_pin = machine.Pin(32) i2c = machine.I2C(scl=scl_pin, sda=sda_pin, speed=400000) ts.init(i2c) while True: ts.read() time.sleep(0.2)