write()

描述

写入值到伺服马达,藉以控制伺服马达。对标准的伺服马达来说,不同的参数代表不同的角度,呼叫完 write() 后伺服马达将会转到对应的角度。如果使用的马达是可以持续旋转的,参数为 0 时马达会全速往某个方向转动,参数为 180 时会全速往另一个方向转动,参数为 90 时马达不会转动。

语法


servo.write(angle)

参数

angle:用来控制伺服马达的值,该值的范围从 0 ~ 180

范例

#include <Servo.h> 

Servo myservo;

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

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.