writeMicroseconds()

描述

写入值到伺服马达,单位为微秒,藉以控制伺服马达。对标准的伺服马达来说,这个值控制的是角度,当参数为 1000 时,伺服马达会转到逆时钟方向所能到的最大角度,当参数为 2000 时,伺服马达会转到顺时钟方向所能到的最大角度,当参数为 1500 时,伺服马达会转到中点。

有些伺服马达并不依照上述的标准製造,这时必须查看该伺服马达的规格书,才有办法让马达依照我们的想法动作,或是自己实验不同的参数所对应的动作。

如果使用的马达是可以持续旋转的,使用 writeMicrosecond() 的行为模式会与 write() 相似,请参考 write() 的描述。

语法


servo.writeMicroseconds(uS)

参数

uS:用来控制伺服马达的值,单位为微秒

范例

#include <Servo.h> 

Servo myservo;

void setup() 
{ 
  myservo.attach(9);
  myservo.writeMicroseconds(1500);  // 让马达转到中点
} 

void loop() {} 

See also

attach()
read()


函式库参考主页面

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.