我正在用 python 编写一个程序,其中在特定时间移动伺服系统是项目的关键部分。为了实现这一点,我正在使用 pyfirmata 库。
我尝试了两种延迟方法,但似乎都不起作用。当我运行代码时,伺服器第一次转动,但在延迟之后,它没有转动,程序只是停止,而不是将伺服器移动到 0 度然后停止。
这是在 pyfirmata 库中内置 board.pass_time() 的那个:
from pyfirmata import Arduino, util
import time
board = Arduino('COM3')
servo = board.get_pin('d:9:s')
servo.write(180) #This works and turns the servo
time.sleep(1)
servo.write(0) #This time the servo does not turn, then the program ends
这是带有 time.sleep() 的那个:
from pyfirmata import Arduino, util
board = Arduino('COM3')
servo = board.get_pin('d:9:s')
servo.write(180) #This works and turns the servo
board.pass_time(1)
servo.write(0) #This time the servo does not turn, then the program ends
如果有人可以提供帮助,我将不胜感激。
谢谢你,大卫