run()

描述

命令伺服机转动至 setPosition() 设定的目标位置。

呼叫 run() 后,您的程式可以去做其他事情,转动伺服机的工作会在背景执行,如果想知道伺服机是否转到目标位置,可以呼叫 isMoving()isServoMultiMoving() 来检查。

请注意,当伺服机处于脱力状态时,此函式将会让伺服机立即出力,此时请避免以手大力转动伺服机,以免受伤或使伺服机损坏。

语法


servo.run()

参数

servoServo 型别的变数。

回传

范例

#include <Servo86.h> 
 
Servo myservo;
 
void setup() 
{ 
  myservo.attach(9);
  myservo.setPosition(1500); // 设定以最快速度转动到 1500us 角度 (初次转动必为最快速度)
  myservo.run(); // 转动伺服机
  delay(1000); // 停在 1500us 角度约 1 秒
  myservo.setPosition(1000, 1000); // 设定转到 1000us 角度,用时 1 秒
  myservo.run(); // 转动伺服机
} 
 
void loop() {} 

See also

setVelocity()
setPosition()


函式库参考主页面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.