setPosition()
描述
設定伺服機的目標角度。
語法
servo.setPosition(position)
servo.setPosition(position, time)
參數
servo
:AIServo
型別的變數。
position
:浮點數型別的目標角度,例如 90.0,目標位置單位為”度”,即伺服機的 90 度。
time
(可選):轉到目標角度要花費的時間,若沒有輸入值或輸入值為 0,代表伺服機將會以最快的速度轉動。
回傳
無
範例
#include <AIServo86.h> AIServoPort(ROBOTIS, AX12) bus; AIServo myservo; void setup() { bus.begin(Serial1, 1000000); myservo.attach(bus, 9); myservo.setPosition(150); // 設定以最快速度轉動到 150 度 myservo.run(); // 轉動伺服機 myservo.setPosition(100, 1000); // 設定轉到 100 度,用時 1 秒 myservo.run(); // 轉動伺服機 } void loop() {}
See also
- attach()
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.