positions[]
描述
存放機器人動作幀的整數陣列,每個陣列元素的值對應一個機器人伺服機的位置,單位為 us。
若 ServoFrame 在初始化時,沒有指定載入動作幀檔案,則使用者可改由直接設定此陣列的元素值來設定動作幀。
語法
myframe.positions[channel]
參數
myframe:ServoFrame 型別的物件。
channel:指定陣列元素,範圍為 0 ~ 44。第 n 個元素值代表要指定給第 n 個 Servo 的位置,請見下面範例說明。(注意:在 86Duino One 上所有陣列元素都有效;在86Duino EduCake 上只有 0 ~ 25 的範圍有效;在 86Duino Zero 上只有 0 ~ 16 的範圍有效。)
回傳
無
範例
#include <Servo86.h>
Servo myservo0; // 第 0 個 Servo
Servo myservo1; // 第 1 個 Servo
Servo myservo2; // 第 2 個 Servo
ServoFrame myframe; // 宣告一個動作幀物件
void setup()
{
myservo0.attach(9);
myservo1.attach(11);
myservo2.attach(5);
myframe.positions[0] = 1800; // 設定動作幀內容
myframe.positions[1] = 1300;
myframe.positions[2] = 2000;
// 設定以 500ms 的時間將伺服機由當前位置轉動到 myframe 指定的位置,即令:
// myservo0 轉動到 position[0],
// myservo1 轉動到 position[1] 位置,
// myservo2 轉動到 position[2] 位置。
myframe.setPositions(500, myservo0 , myservo1, myservo2);
servoMultiRun(); // 命令所有伺服機開始轉動
}
void loop() {}
See also
- setPostions()
- playPositions()
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
