read()

説明

サーボの角度を読み取ります。

構文

servo.read()

パラメータ

servo: AIServo 型の変数。

戻り値

サーボの現在の角度。サーボが力を生成していない場合、戻り値は -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() {}

参照

attach()

write()


ライブラリリファレンスページ

86Duino リファレンス資料のテキストは、Arduino リファレンス資料 から改変されており、Creative Commons Attribution-Share Alike 3.0 License に基づいてライセンスされています。リファレンス資料内のコード例はパブリックドメインとして公開されています。