from machine import Pin
from time import sleep
def giro(pin):
    global v
    v = not v
def vel(pin):
    global t
    if t == 0.03:
        t = 0.5
    else:
        t = 0.03
def motor(x):
    A1.value(int(x[0]))
    B1.value(int(x[1]))
    A0.value(int(x[2]))
    B0.value(int(x[3]))
A1 = Pin(22, Pin.OUT)
B1 = Pin(21, Pin.OUT)
A0 = Pin(23, Pin.OUT)
B0 = Pin(19, Pin.OUT)
push1 = Pin(14, Pin.IN, Pin.PULL_UP)
push1.irq(trigger=Pin.IRQ_FALLING, handler=vel)
push2 = Pin(27, Pin.IN, Pin.PULL_UP)
push2.irq(trigger=Pin.IRQ_FALLING, handler=giro)
lista = ["1100", "0110", "0011", "1001"]
v = 0
i = 0
t = 0.03
while True:
    motor(lista[i])
    if v == 0:
        i += 1
        if i > 3:
            i = 0
    else:
        i -= 1
        if i < 0:
            i = 3
    sleep(t)