import machine
from machine import Pin, Timer
import time
from time import sleep
SerA = machine.Pin(32)
SerB = machine.Pin(33)
SerC = machine.Pin(22)
SerD = machine.Pin(23)
pwmSerA = machine.PWM(SerA)
pwmSerB = machine.PWM(SerB)
pwmSerC = machine.PWM(SerC)
pwmSerD = machine.PWM(SerD)
pwmSerA.freq(50)
pwmSerB.freq(50)
pwmSerC.freq(50)
pwmSerD.freq(50)
Key_Up = const(0)
Key_Down = const(1)
Numpad = [['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
['*', '0', '#']]
Rows = [19, 18, 5, 17]
Cols = [16, 4, 0]
pines_Rows = [Pin(pin_name, mode = Pin.OUT) for pin_name in Rows]
pines_Cols = [Pin(pin_name, mode = Pin.IN, pull = Pin.PULL_DOWN) for pin_name in Cols]
def Start():
for Row in range(0, 4):
for Col in range(0, 3):
pines_Rows[Row].value(0)
def Scan(Row, Col):
""" Escaneo de teclado """
pines_Rows[Row].value(1)
key = None
if pines_Cols[Col].value() == Key_Down:
key = Key_Down
if pines_Cols [Col].value() == Key_Up:
key = Key_Up
pines_Rows[Row].value(0)
return key
print("iniciando .............Presione una tecla: ")
Start()
while True:
for Row in range(4):
for Col in range(3):
Key = Scan(Row, Col)
if Key == Key_Down:
print("Tecla: ", Numpad[Row][Col])
last_key_press = Numpad[Row][Col]
if Numpad[Row][Col] != '1':
pwmSerA.duty(25)
pwmSerB.duty(25)
pwmSerC.duty(25)
pwmSerD.duty(25)
print("CLOSE")
else:
pwmSerA.duty(75)
pwmSerB.duty(75)
pwmSerC.duty(75)
pwmSerD.duty(75)
print("OPEN")
sleep(0.2)