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.