isMoving()
描述
檢查伺服機是否正在轉動。
語法
servo.isMoving()
參數
servo
:AIServo
型別的變數。
回傳
若伺服機正在轉動,回傳 true,其他狀況下(如:伺服機暫停、停止、釋放或到達目標位置)則回傳 false。
範例
#include <AIServo86.h> AIServoPort(ROBOTIS, AX12) bus; AIServo myservo; void setup() { bus.begin(Serial1, 1000000); myservo.attach(bus, 9); myservo.write(150); // 將伺服機轉到 150 度 delay(1000); myservo.setPosition(180, 3000); // 設定伺服機的目標角度:180 度,時間: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
- attach()
- setPosition()
- isAIServoMultiMoving()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.