setVelocity()

描述

設定下一次呼叫 write()run() 時,伺服機的轉動速度。

請注意,若您呼叫 setPosition() 時設定了轉動時間,則此函式設定的轉速將不會有效果。

語法


servo.setVelocity(value)

參數

servoServo 型別的變數。

value:伺服機的轉速,可輸入整數和浮點數型別的數值。當輸入整數時,轉速的單位是 us/s,例如輸入 1000,代表即每秒轉 1000us 的角度。當輸入的是浮點數時,轉速的單位是角度/s,例如輸入 1.5,代表即每秒轉 1.5 度。若輸入值為 0 或 0.0,代表伺服機將會以最快的速度轉動。

回傳

範例

#include <Servo86.h> 
 
Servo myservo;
 
void setup() 
{ 
  myservo.attach(9);
  myservo.write(1500); // 將伺服機轉動到 1500us 角度
  myservo.setVelocity(1000); // 設定速度 1000us/s
  myservo.write(900); // 啟動伺服機,用 1000us/s 的速度轉到 900us 角度
} 
 
void loop() {} 

See also

write()
writeMicroseconds()
setPosition()
run()


函式庫參考主頁面

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.