语言:MicroPyhton
硬件:
接线示意图
MicroPyhton代码:
import utime
from machine import Pin, PWM
pin1=PWM(Pin(14),freq=1000)
pin2=PWM(Pin(12),freq=1000)
def car_forward():
pin1.duty(1000) # 正转
pin2.duty(0)
def car_stop(): #停止
pin1.duty(0)
pin2.duty(0)
def car_backward():
pin1.duty(0) # 反转
pin2.duty(1000)
car_forward()
utime.sleep(2)
car_stop()
utime.sleep(2)
car_backward()
utime.sleep(2)
car_stop()