代码跟教程的代码一模一样。使用传感器扩展板,用的5v电池供电。但是舵机只转动一下,然后就没反应。用的sg90的舵机
-
s1 = Servo(1) s1.speed(50) while(1): s1.angle(90) time.sleep(100) s1.angle(-60,1000) time.sleep(1000) S1.angle(0)
-
下面这个代码也是一样,舵机就只转动一下
from pyb import Servo import time #180°的舵机 s1 = Servo(1) # servo on position 1 (P7) s1.angle(0) # move to 0 degrees time.sleep(1000) while(1): s1.angle(90) # move to 90 degrees time.sleep(600) s1.angle(45) # move to 180 degrees time.sleep(0) s1.angle(-90) # move to 90 degrees time.sleep(600) s1.angle(-45) # move to -90 degrees time.sleep(600) s1.angle(0) # move to 0 degrees time.sleep(1000) #s1.angle(-60, 1500) # move to -60 degrees in 1500ms #s1.speed(50) # for continuous rotation servos
-
代码不对,应该是 time.sleep_ms()不是time.sleep()
-
@kidswong999 但这代码跟教程上一样啊,教程上能行,为啥我们这就不能行
-
@rvwk 因为版本更新后,time.sleep的功能变了,以前是延时毫秒,现在是延时秒。