from machine import Pin
from time import sleep
def cam_dir(y):
    global dire
    dire = dire*(-1)
   
def cam_vel(y):
    global t
    if t == 0.1:
        t = 0.01
    else:
        t = 0.1
        
def motor(x):
    A1.value(int(x[0]))
    B1.value(int(x[1]))
    A0.value(int(x[2]))
    B0.value(int(x[3]))
A0=Pin(23,Pin.OUT)
A1=Pin(21,Pin.OUT)
B0=Pin(22,Pin.OUT)
B1=Pin(19,Pin.OUT)
BTN=Pin(26,Pin.IN,Pin.PULL_UP)
BTN.irq(trigger=Pin.IRQ_FALLING,handler=cam_dir)
BTN2=Pin(12,Pin.IN,Pin.PULL_UP)
BTN2.irq(trigger=Pin.IRQ_FALLING,handler=cam_vel)
lista=["1100","0110","0011","1001"]
dire=1
t=0.01
n=0
m=0
while(1):
    motor(lista[n])
    sleep(t)
    n+=dire
    if n > 3:
        n = 0
    elif n < 0:
        n = 3