from machine import Pin,PWM
from time import sleep
def cambio (x):
global dir
if dir==0:
dir=1
else:
dir=0
def fun (y):
global i
i=i+1
if i>=2:
i=0
b1= Pin(12,Pin.IN,Pin.PULL_UP)
b1.irq(trigger=Pin.IRQ_FALLING,handler=cambio)
b2= Pin(13,Pin.IN,Pin.PULL_UP)
b2.irq(trigger=Pin.IRQ_FALLING,handler=fun)
pwm=PWM(Pin(19), freq=1000)
d1=Pin(22,Pin.OUT) #anti horario
d2=Pin(23,Pin.OUT)
i=0
dir=0
lista=[400,1023]
while (1):
pwm.duty(lista[i])
if dir==0:
d1.on()
d2.off()
else:
d1.off()
d2.on()