from machine import Pin
from keypad import Keypad
from time import sleep
# Define GPIO pins for rows
row_pins = [Pin(25),Pin(26),Pin(27),Pin(14)]
# Define GPIO pins for columns
column_pins = [Pin(23),Pin(22),Pin(19),Pin(18)]
# Define keypad layout
keys = [
['1', '2', '3', 'A'],
['4', '5', '6', 'B'],
['7', '8', '9', 'C'],
['*', '0', '#', 'D']]
keypad = Keypad(row_pins, column_pins, keys)
while True:
key_pressed = keypad.read_keypad()
print(key_pressed)
if key_pressed:
tecla=float(key_pressed)
print(tecla)
print("Key pressed:", key_pressed)
tecla+=1
print(tecla)
sleep(0.5) # debounce and delay