from time import sleep_ms from machine import Pin, I2C from gt911 import GT911 import LCD # Touch Screen Initialization rst_pin = Pin(10, Pin.OUT) irq_pin = Pin(11) sda_pin = Pin(8) scl_pin = Pin(9) touch = GT911( I2C(0, scl=scl_pin, sda=sda_pin, freq=100_000), rst_pin, irq_pin ) touch.init(touch_points=1, refresh_rate=50) # LCD Display initialization Black = LCD.RGB(0,0,0) Red = LCD.RGB(100,0,0) Green = LCD.RGB(0,100,0) Blue = LCD.RGB(0,0,100) White = LCD.RGB(100,100,100) LCD.Init() LCD.Clear(Black) LCD.Title('Colors.py', White, Black) R = 0; G = 0; B = 0; LCD.Text2('R', 10, 50, Red, Black) LCD.Text2('G', 10, 150, Green, Black); LCD.Text2('B', 10, 250, Blue, Black); while True: num_points, points_data = touch.read_points() if(num_points > 0): tx = points_data[0][0] ty = points_data[0][1] print(tx, ty) if(ty < 100): LCD.Box(50, 50, R+50, 100, Black) R = max(0, min(250, tx - 50)) LCD.Box(50, 50, R+50, 100, Red) elif(ty < 200): LCD.Box(50, 150, G+50, 200, Black) G = max(0, min(250, tx - 50)) LCD.Box(50, 150, G+50, 200, Green) else: LCD.Box(50, 250, B+50, 300, Black) B = max(0, min(250, tx - 50)) LCD.Box(50, 250, B+50, 300, Blue) Color = LCD.RGB(R, G, B) LCD.Solid_Box(350, 50, 450, 300, Color)