from machine import Pin, PWM
import time
in1 = Pin(18, Pin.OUT)
in2 = Pin(5, Pin.OUT)
in3 = Pin(16, Pin.OUT)
in4 = Pin(4, Pin.OUT)
enA = PWM(Pin(21))
enB = PWM(Pin(2))
enA.freq(1000)
enB.freq(1000)
while True:
# motor 1 forward direction
in1.on()
in2.off()
enA.duty(1023)
time.sleep(1)
# motor 1 reverse direction
in1.off()
in2.on()
enA.duty(50)
time.sleep(1)
# motor 2 forward direction
in3.on()
in4.off()
enB.duty(1023)
time.sleep(1)
# motor 2 reverse direction
in3.off()
in4.on()
enB.duty(50)
time.sleep(1)