# Testing a numeric keypad # pins 2/3/4/5 = rows (input) # pins 6/7/8/9 = columns (output) from machine import Pin import time import LCD def GetKey(): R0 = Pin(18,Pin.IN,Pin.PULL_UP) R1 = Pin(19,Pin.IN,Pin.PULL_UP) R2 = Pin(20,Pin.IN,Pin.PULL_UP) R3 = Pin(21,Pin.IN,Pin.PULL_UP) C0 = Pin(11,Pin.OUT) C1 = Pin(10,Pin.OUT) C2 = Pin(9,Pin.OUT) Key = 255 C0.value(0) C1.value(1) C2.value(1) time.sleep(0.001) if(R0.value() == 0): Key = 1 if(R1.value() == 0): Key = 4 if(R2.value() == 0): Key = 7 if(R3.value() == 0): Key = 10 C0.value(1) C1.value(0) C2.value(1) time.sleep(0.001) if(R0.value() == 0): Key = 2 if(R1.value() == 0): Key = 5 if(R2.value() == 0): Key = 8 if(R3.value() == 0): Key = 0 C0.value(1) C1.value(1) C2.value(0) time.sleep(0.001) if(R0.value() == 0): Key = 3 if(R1.value() == 0): Key = 6 if(R2.value() == 0): Key = 9 if(R3.value() == 0): Key = 11 return(Key) def ReadKey(): X = GetKey() while(X == 255): X = GetKey() Y = GetKey() while(Y != 255): Y = GetKey() return(X) # Main Routine White = LCD.RGB(250,250,250) Navy = LCD.RGB(0,0,50) X = 0 Y = 0 Z = 0 T = 0 LCD.Init() LCD.Clear(Navy) LCD.Text2('T:',50,50,White,Navy) LCD.Text2('Z:',50,100,White,Navy) LCD.Text2('Y:',50,150,White,Navy) LCD.Text2('X:',50,200,White,Navy) LCD.Number2(T,9,3,100,50,White,Navy) LCD.Number2(Z,9,3,100,100,White,Navy) LCD.Number2(Y,9,3,100,150,White,Navy) LCD.Number2(X,9,3,100,200,White,Navy) while(1): Key = ReadKey() if(Key<10): X = (X*10)+Key*0.001 LCD.Number2(X,9,3,100,200,White,Navy) if(Key==10): T=Z Z=Y Y=X X=0 LCD.Number2(T,9,3,100,50,White,Navy) LCD.Number2(Z,9,3,100,100,White,Navy) LCD.Number2(Y,9,3,100,150,White,Navy) LCD.Number2(X,9,3,100,200,White,Navy) if(Key==11): X=int(X/10) LCD.Number2(X,9,3,100,200,White,Navy)