from machine import Pin
from time import sleep
# funcion de las interrupciones para el encoder
def escoderA(x):
global cnt # se mantiene activa en el programa
if canal_B.value() == 1:
cnt += 1
if cnt >= 30 or cnt <= 30: # los led se apagan cuando llegue a 30 pulsos
ledrojo.off()
ledazul.off()
def escoderB(x):
global cnt
if canal_A.value() == 1:
cnt -= 1
if cnt >= 30 or cnt <= -30:
ledrojo.off()
ledazul.off()
# funcion de las interrupciones para los botones
def botonRojo(x):
ledrojo.on()
a.on()
b.on()
def botonAzul(x):
ledazul.on()
c.on()
d.on()
cnt = 0 #variable global
#configuracion
canal_A = Pin(16, Pin.IN)
canal_A.irq(trigger=Pin.IRQ_FALLING, handler=escoderA)
canal_B = Pin(4, Pin.IN)
canal_B.irq(trigger=Pin.IRQ_FALLING, handler=escoderB)
ledrojo = Pin(23, Pin.OUT)
ledazul = Pin(22, Pin.OUT)
a=Pin(19,Pin.OUT)
b=Pin(18,Pin.OUT)
c=Pin(5,Pin.OUT)
d=Pin(17,Pin.OUT)
#declaracion de los push-botton
push1 = Pin(27, Pin.IN, Pin.PULL_UP)
push1.irq(trigger=Pin.IRQ_FALLING, handler=botonRojo)
push2 = Pin(14, Pin.IN, Pin.PULL_UP)
push2.irq(trigger=Pin.IRQ_FALLING, handler=botonAzul)
#programa principal
while True:
sleep(1)