stop()
描述
停止伺服機的轉動。
呼叫此函式後,伺服機會在當前的位置上立即停止。此函式的行為和 pause() 不同,您無法透過 resume() 讓伺服機恢復轉動,必須重新設定目標位置並呼叫 run(),或者呼叫 write() 或 writeMicroseconds() 才能讓伺服機再次轉動。
請注意,伺服機在停止狀態仍會出力,此時請勿用手大力轉動伺服機,否則容易造成伺服機損壞。
語法
servo.stop()
參數
servo
:Servo
型別的變數。
回傳
無
範例
#include <Servo86.h> Servo myservo; void setup() { myservo.attach(9); myservo.write(1500); // 將伺服機轉到 1500us 初始位置 myservo.run(); // 啟動伺服機 delay(100); myservo.setPosition(1800, 3000); // 設定伺服機的目標角度:1800us,時間:3 秒 myservo.run(); delay(2000); // 讓伺服機轉動 2 秒 myservo.stop(); // 停止伺服機 } void loop() {}
See also
- setPosition()
- run()
- pause()
- resume()
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.