isMoving()
描述
回报伺服机是否正处于转动状态。
语法
servo.isMoving()
参数
servo:Servo 型别的变数。
回传
若伺服机正在转动,回传 true;其他状况下(如:伺服机暂停、停止、释放或已到达目标位置)则回传 false。
范例
#include <Servo86.h>
Servo myservo;
void setup()
{
myservo.attach(9);
myservo.write(1500); // 将伺服机转到 1500us 初始位置
delay(1000);
myservo.setPosition(1800, 3000); // 设定伺服机的目标角度:1800us,时间:3 秒
myservo.run();
delay(1000); // 伺服机转动 1 秒
if(myservo.isMoving() == true) // 检查伺服机是否转到目标角度
Serial.println("The servo is moving...");
else
Serial.println("The servo stops at target position");
delay(3000); // 让伺服机转动至目标角度
if(myservo.isMoving() == true) // 检查伺服机是否转到目标角度
Serial.println("The servo is moving...");
else
Serial.println("The servo stops at target position");
}
void loop() {}
See also
- write()
- writeMicroseconds()
- setPosition()
- run()
- pause()
- resume()
- stop()
- release()
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.
