from machine import Pin
from time import sleep
def  motor(X):
    A1.value(int(X[0]))
    B1.value(int(X[1]))
    A0.value(int(X[2]))
    B0.value(int(X[3]))
   
def  cambio_u(y):
    global d
    d= not d
def  cambio_v(z):
    global v
    v = v - 0.03
    if v < 0.03:
        v = 1   
A1 = Pin(22,Pin.OUT)
A0 = Pin(23,Pin.OUT)
B1 = Pin(21,Pin.OUT)
B0 = Pin(19,Pin.OUT)
push1=Pin(14,Pin.IN,Pin.PULL_UP)
push2=Pin(12,Pin.IN,Pin.PULL_UP)
push1.irq(trigger=Pin.IRQ_FALLING, handler=cambio_u)
push2.irq(trigger=Pin.IRQ_FALLING, handler=cambio_v)
lista=["1100","0110","0011","1001"]
i = 0
d = 0   
v = 0.25  
while (1):
    motor(lista[i])
    sleep(v)
    if d == 0:
        i = i + 1
        if i > 3:
            i = 0
    else:
        i = i - 1
        if i < 0:
            i = 3