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.