from machine import Pin
from time import sleep
def motor (x):
A.value(int(x[0]))
B.value(int(x[1]))
C.value(int(x[2]))
D.value(int(x[3]))
def direc (y):
global direccion
direccion = not direccion
def vel (z):
global v
v = v - 0.03
if v < 0.03:
v = 1
A = Pin(23,Pin.OUT)
B = Pin(22,Pin.OUT)
C = Pin(21,Pin.OUT)
D = Pin(19,Pin.OUT)
push_1 = Pin(12,Pin.IN,Pin.PULL_UP)
push_2 = Pin(14,Pin.IN,Pin.PULL_UP)
lista = ["1100", "0110", "0011", "1001"]
push_1.irq(trigger=Pin.IRQ_FALLING, handler=direc)
push_2.irq(trigger=Pin.IRQ_FALLING, handler=vel)
n=0
direccion=0
v=0.5
while(1):
motor(lista[n])
sleep(v)
if direccion == 0:
n=n+1
if n > 3:
n = 0
else:
n=n-1
if n < 0:
n = 3