isMoving()

描述

檢查伺服機是否正在轉動。

語法

servo.isMoving()

參數

servoAIServo 型別的變數。

回傳

若伺服機正在轉動,回傳 true,其他狀況下(如:伺服機暫停、停止、釋放或到達目標位置)則回傳 false。

範例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

#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()


函式庫參考主頁面

86Duino 參考資料中的文字修改自 Arduino 參考資料,並根據 知識共享署名-許可證方式共享 3.0 授權相同。參考資料中的程式碼範例已發佈到公共領域。