from machine import Pin
from time import sleep
def mot(x, y):
    A1.value(int(x[0]))
    A2.value(int(x[1]))
    B1.value(int(x[2]))
    B2.value(int(x[3]))
    sleep(y)
A1 = Pin(23, Pin.OUT)
A2 = Pin(21, Pin.OUT)
B1 = Pin(22, Pin.OUT)
B2 = Pin(19, Pin.OUT)
push1_dir = Pin(14, Pin.IN, Pin.PULL_UP)   
push2_vel = Pin(12, Pin.IN, Pin.PULL_UP)   
pasos= ["1100", "0110", "0011", "1001"]
direccion = 1
velocidad = 0
def direccion_cambio(pin):
    global direccion
    direccion = not direccion
    sleep(0.05)
def cambio_velocidad(pin):
    global velocidad
    velocidad = not velocidad
    sleep(0.05)
push1_dir.irq(trigger=Pin.IRQ_FALLING, handler=direccion_cambio)
push2_vel.irq(trigger=Pin.IRQ_FALLING, handler=cambio_velocidad)
while (1):
    if direccion == 1:
        pasos(pasos)
    else:
        pasos = pasos_antiorario
    if velocidad == 0:
        tiempo = 0.5
    else:
        tiempo = 0.05
    for i in pasos:
        mot(i, tiempo)