from machine import Pin
import time
KEYMAP = [
["1","2","3","A"],
["4","5","6","B"],
["7","8","9","C"],
["*","0","#","D"],
]
rows = [Pin(p, Pin.OUT) for p in [23,22,21,19]]
cols = [Pin(p, Pin.IN, Pin.PULL_UP) for p in [5,4,2,15]]
for r in rows:
r.value(1) # repouso HIGH
print("iniciou - segure uma tecla")
while True:
for i, r in enumerate(rows):
r.value(0)
time.sleep_ms(2)
for j, c in enumerate(cols):
if c.value() == 0:
print("Tecla:", KEYMAP[i][j])
time.sleep_ms(300)
t0 = time.ticks_ms()
while c.value() == 0 and time.ticks_diff(time.ticks_ms(), t0) < 2000:
time.sleep_ms(20)
r.value(1)
time.sleep_ms(20)