import timeimport RPi.GPIO as GPIO# 设置模式GPIO.setmode(GPIO.BCM)# 设置端口号GPIO.setup(21, GPIO.OUT)p = GPIO.PWM(21, 50) # channel=12 frequency=50Hzp.start(0)try:while 1:for dc in range(0, 101, 5):p.ChangeDutyCycle(dc)time.sleep(0.1)for dc in range(100, -1, -5):p.ChangeDutyCycle(dc)time.sleep(0.1)except KeyboardInterrupt:passp.stop()GPIO.cleanup()
如果觉得《树莓派 --- 控制舵机转动代码Python》对你有帮助,请点赞、收藏,并留下你的观点哦!