from machine import Pin
from time import sleep
def direccion(y):
    global m
    m=not m
def velocidad(y):
    global t
    t=t-0.25
    if t<0.25:
        t=0.5
def mot(x):
  a1.value(int(x[0]))
  b1.value(int(x[1]))
  a2.value(int(x[2]))
  b2.value(int(x[3]))
a1=Pin(23,Pin.OUT)
a2=Pin(22,Pin.OUT)
b1=Pin(16,Pin.OUT)
b2=Pin(4,Pin.OUT)
push1=Pin(25,Pin.IN,Pin.PULL_UP)
push1.irq(trigger=Pin.IRQ_FALLING,handler=direccion)
push2=Pin(26,Pin.IN,Pin.PULL_UP)
push2.irq(trigger=Pin.IRQ_FALLING,handler=velocidad)
lista=["1100","0110","0011","1001"]
m=0
n=0
t=0.5
while(1):
  if m==0:
    mot(lista[n])
    n=n+1
    if n>3:
        n=0
    sleep(t)
  else:
    mot(lista[n])
    n=n-1
    if n<0:
        n=3
    sleep(t)