write()
描述
设定伺服机目标角度,并且往目标角度转动。
请注意,呼叫此函式后会让伺服机立即出力,请避免以手大力转动伺服机,以免受伤或损坏伺服机。
语法
servo.write(position)
参数
servo
:Servo
型别的变数。
position
:目标角度,可输入整数和浮点数型别的数值,当输入整数时,例如 1500,此时目标位置会被视为 us 单位,即对应 PWM 脉波为 1500us 的伺服机位置。当输入的是符点数时,例如 90.0,此时目标位置会被视为度单位,即伺服机的 90 度位置。
回传
范例
#include <Servo86.h> Servo myservo; void setup() { myservo.attach(9); myservo.write(90.0); // 让伺服机转到 90 度 } void loop() {}
See also
- writeMicroseconds()
- read()
- readMicroseconds()
- setVelocity()
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.