from machine import Pin, PWM
from time import sleep
dir_1 = Pin(21,Pin.OUT)
dir_2 = Pin(22,Pin.OUT)
uno = PWM(Pin(23),freq=1000)
push = Pin(14,Pin.IN,Pin.PULL_UP)
def motor(x,y,z):
dir_1.value(x)
dir_2.value(y)
uno.duty(z)
n = 0
while(1):
if push.value() == 0:
sleep(0.03)
n = n + 1
if n > 4:
n = 1
while push.value() == 0:
sleep(0.2)
if n == 0:
motor(1, 0, 500)
elif n == 1:
motor(1, 0, 1000)
elif n == 2:
motor(0, 1, 1000)
elif n == 3:
motor(0, 1, 500)
sleep(0.05)