read()

描述

讀取伺服機角度。

語法

servo.read()

參數

servoAIServo 型別的變數。

回傳

伺服機目前的角度,如果伺服機尚未出力,回傳值為 -1。(單位:度)

範例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

#include <AIServo86.h>

 

AIServoPort(ROBOTIS, AX12) bus;

AIServo myservo;

double position;

 

void setup()

{

  bus.begin(Serial1, 1000000);

  myservo.attach(bus, 9);

  myservo.write(90.0);  // 讓伺服機轉到 90 度

  delay(100); // 延遲 100 毫秒

  position = read(); // 讀取目前角度

  Serial.println(position);

}

 

void loop() {}

See also

attach()

write()


函式庫參考主頁面

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