from time import sleep_ms from machine import Pin, I2C from gt911 import GT911 import LCD_16x24 as LCD import math # 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 Initialization White = LCD.RGB(155,155,155) Black = LCD.RGB(0,0,0) Grey = LCD.RGB(30, 30, 30) def Place_Button(bx, by, x, y, Label): n = len(Label) Sx = 480//x Sy = 320//y x0 = bx*Sx y0 = by*Sy LCD.Box(x0, y0, min(479, x0 + Sx), min(319, y0 + Sy), White) LCD.Text3(Label, x0+Sx//2-8*n, y0+Sy//2-10, White, Black) def Draw_Keyboard(x,y): Sx = 480//x Sy = 320//y for i in range(0,y+1): LCD.Line(0,i*Sy,479,i*Sy, Grey) for i in range(0,x+1): LCD.Line(i*Sx,0,i*Sx,319, Grey) Place_Button(0, 2, x, y, '1') Place_Button(1, 2, x, y, '2') Place_Button(2, 2, x, y, '3') Place_Button(3, 2, x, y, '*') Place_Button(4, 2, x, y, '1/x') Place_Button(0, 3, x, y, '4') Place_Button(1, 3, x, y, '5') Place_Button(2, 3, x, y, '6') Place_Button(3, 3, x, y, '/') Place_Button(4, 3, x, y, '+/-') Place_Button(0, 4, x, y, '7') Place_Button(1, 4, x, y, '8') Place_Button(2, 4, x, y, '9') Place_Button(3, 4, x, y, '+') Place_Button(4, 4, x, y, 'clx') Place_Button(0, 5, x, y, '.') Place_Button(1, 5, x, y, '0') Place_Button(2, 5, x, y, 'ent') Place_Button(3, 5, x, y, '-') Place_Button(4, 5, x, y, 'clr') #LCD.Text3('T', 0, 5, White, Black) #LCD.Text3('Z', 0, 30, White, Black) LCD.Text3('Y', 0, 55, White, Black) LCD.Text3('X', 0, 80, White, Black) def Read_Keypad(x, y): Sx = 480//x Sy = 320//y num_points, points_data = touch.read_points() while(num_points == 0): num_points, points_data = touch.read_points() sleep_ms(30) tx = points_data[0][0] // Sx ty = points_data[0][1] // Sy while(num_points > 0): num_points, points_data = touch.read_points() sleep_ms(30) return(tx, ty) def Push(): global X, Y, Z, T, f0 T = Z Z = Y Y = X X = 0 f0 = 1 def Display(): global X, Y, Z, T, f0, f1 if(f0 == 1): #LCD.Number3(T, 9, 4, 20, 5, White, Black) #LCD.Number3(Z, 9, 4, 20, 30, White, Black) LCD.Number3(Y, 9, 4, 20, 55, White, Black) f0 = 0 LCD.Number3(X, 9, 4, 20, 80, White, Black) LCD.Init() LCD.Clear(Black) Draw_Keyboard(9, 6) X = Y = Z = T = 0 f0 = 1 f1 = 0 while(1): Display() [x, y] = Read_Keypad(9,6) print(x, y) if(y==2): if(x==0): if(f1): Push() f1 = 0 X = 10*X + 1 elif(x==1): if(f1): Push() f1 = 0 X = 10*X + 2 elif(x==2): if(f1): Push() f1 = 0 X = 10*X + 3 elif(x==3): X = Y * X Y = Z Z = T f0 = 1 f1 = 1 elif(x==4): X = 1/X f1 = 1 elif(y==3): if(x==0): if(f1): Push() f1 = 0 X = 10*X + 4 elif(x==1): if(f1): Push() f1 = 0 X = 10*X + 5 elif(x==2): if(f1): Push() f1 = 0 X = 10*X + 6 elif(x==3): X = Y / X Y = Z Z = T f0 = 1 f1 = 1 elif(x==4): X = -X elif(y==4): if(x==0): if(f1): Push() f1 = 0 X = 10*X + 7 elif(x==1): if(f1): Push() f1 = 0 X = 10*X + 8 elif(x==2): if(f1): Push() f1 = 0 X = 10*X + 9 elif(x==3): X = Y + X Y = Z Z = T f0 = 1 f1 = 1 elif(x==4): X = 0 elif(y==5): if(x==0): pass elif(x==1): if(f1): Push() f1 = 0 X = 10*X + 0 elif(x==2): Push() elif(x==3): X = Y - X Y = Z Z = T f0 = 1 f1 = 1 elif(x==4): X = X // 10