stop()

描述

停止轉動中的伺服機。呼叫此函式後,伺服機會在當前的位置上停止轉動,同時會清除設定過的目標角度和時間,並視當前角度為目標角度。

此函式的行為和 pause() 不同,您無法透過 resume() 讓伺服機恢復轉動,必須要重新設定目標角度,然後呼叫 run()write() 其中之一才能讓伺服機開始轉動。

請注意,停止後的伺服機仍會出力,請勿用手大力轉動,否則容易造成伺服機損壞。

語法


servo.stop()

參數

servoAIServo 型別的變數。

回傳

範例

#include <AIServo86.h> 

AIServoPort(ROBOTIS, AX12) bus;
AIServo myservo;

void setup() 
{ 
  bus.begin(Serial3, 1000000);
  myservo.attach(bus, 3);
  myservo.write(150);  // 將伺服機轉到 150 度
  myservo.run(); // 啟動伺服機
  delay(600);
} 

void loop()
{
  myservo.setPosition(280, 2000); // 設定伺服機的目標角度:280 度,時間:2 秒
  myservo.run();
  delay(1000); // 讓伺服機轉動 1 秒
  myservo.stop(); // 停止伺服機
  while(1);
} 

See also

attach()
setPosition()
pause()
resume()


函式庫參考主頁面

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.