from machine import Pin
import utime, time
keys = [[1, 2, 3, 'A'],
[4, 5, 6, 'B'],
[7, 8, 9, 'C'],
['*', 0, '#', 'D']]
rows = [26, 22,21,20]
columns = [19,18,17,16]
col_pins = []
row_pins = []
for x in range(0,4):
row_pins.append(Pin(rows[x], Pin.OUT))
col_pins.append(Pin(columns[x], Pin.IN, Pin.PULL_DOWN))
print("Please enter a key from the keypad")
while True:
for row in range(4):
for col in range(4):
row_pins[row].value(1)
if col_pins[col].value():
print("You have pressed:", keys[row][col])
while col_pins[col].value(): # 계속 눌려져 있을 때 오류 방지
pass
utime.sleep(0.3)
row_pins[row].value(0)
time.sleep(0.2)