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
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.