import time
from neopixel import NeoPixel
from machine import Pin
pressed = True
leds = [22, 21, 19, 18, 5, 4, 2, 15]
keys=[["1","2","3","A"],\
["4","5","6","B"],\
["7","8","9","C"],\
["*","0","#","D"]
]
ledRing = NeoPixel(Pin(13, Pin.OUT), 16)
colPins = [ 5, 4, 2, 15]
rowPins = [ 22, 21, 19, 18]
for x in range(4):
colPins[x] = Pin(colPins[x], Pin.OUT)
for x in range(4):
rowPins[x] = Pin(rowPins[x], Pin.OUT)
def Keypad4x4Read(cols,rows, pressing):
for r in rows:
r.value(1)
result=[cols[0].value(),cols[1].value(),cols[2].value(),cols[3].value()]
if max(result)==1:
if pressing:
pressing = False
key=keys[int(rows.index(r))][int(result.index(1))]
return key, pressing
else:
pressing = True
return None, pressing
pin1 = Pin(22,Pin.OUT)
print(pin1.value(1))
print(type(pin1))
cur_num = ""
while True:
key, pressed = Keypad4x4Read(colPins, rowPins, pressed)
if key != None and pressed == False:
if len(cur_num) <= 3:
cur_num += str(key)
else:
ur_num = cur_num[1:]
print(cur_num)
time.sleep(0.05)