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.
