run()

描述

命令伺服機轉動至 setPosition() 設定的目標位置。

呼叫 run() 後,您的程式可以去做其他事情,轉動伺服機的工作會在背景執行,如果想知道伺服機是否轉到目標位置,可以呼叫 isMoving()isServoMultiMoving() 來檢查。

請注意,當伺服機處於脫力狀態時,此函式將會讓伺服機立即出力,此時請避免以手大力轉動伺服機,以免受傷或使伺服機損壞。

語法


servo.run()

參數

servoServo 型別的變數。

回傳

範例

#include <Servo86.h> 
 
Servo myservo;
 
void setup() 
{ 
  myservo.attach(9);
  myservo.setPosition(1500); // 設定以最快速度轉動到 1500us 角度 (初次轉動必為最快速度)
  myservo.run(); // 轉動伺服機
  delay(1000); // 停在 1500us 角度約 1 秒
  myservo.setPosition(1000, 1000); // 設定轉到 1000us 角度,用時 1 秒
  myservo.run(); // 轉動伺服機
} 
 
void loop() {} 

See also

setVelocity()
setPosition()


函式庫參考主頁面

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.