micropython 4x4 matrix input

rows = [
Pin(20, Pin.OUT), Pin(21, Pin.OUT), Pin(22, Pin.OUT), Pin(23, Pin.OUT),
]
columns = [
Pin(16, Pin.IN), Pin(17, Pin.IN), Pin(18, Pin.IN), Pin(19, Pin.IN)
]

keys = [False] * 16
for r in rows:
r.low()
code = ""
while True:
for k in range(16):
if keys[k] == True:
lcd.putstr(str(k))
time.sleep_ms(67)

for r in range(4):
rows[r].high()
for c in range(4):
if columns[c].value() == 1:
keys[c * 4 + r] = True
else:
keys[c * 4 + r] = False
rows[r].low()
lcd.clear()
rows = [
Pin(20, Pin.OUT), Pin(21, Pin.OUT), Pin(22, Pin.OUT), Pin(23, Pin.OUT),
]
columns = [
Pin(16, Pin.IN), Pin(17, Pin.IN), Pin(18, Pin.IN), Pin(19, Pin.IN)
]

keys = [False] * 16
for r in rows:
r.low()
code = ""
while True:
for k in range(16):
if keys[k] == True:
lcd.putstr(str(k))
time.sleep_ms(67)

for r in range(4):
rows[r].high()
for c in range(4):
if columns[c].value() == 1:
keys[c * 4 + r] = True
else:
keys[c * 4 + r] = False
rows[r].low()
lcd.clear()
it displays some random key codes like 3 per time i press 1 key
3 Replies
gooficat
gooficatOP2d ago
like 456 when i press key 1
DarwinWasWrong
GitHub
GitHub - PerfecXX/MicroPython-SimpleKeypad: MicroPython library for...
MicroPython library for interfacing with a keypad matrix - PerfecXX/MicroPython-SimpleKeypad
Tormi
Tormi2d ago
are u sure that keys[c * 4 + r] should not be keys[r* 4 + c] ?

Did you find this page helpful?