write()

描述

設定伺服機目標角度,並且往目標角度轉動。

請注意,呼叫此函式後會讓伺服機立即出力,請避免以手大力轉動伺服機,以免受傷或損壞伺服機。

語法


servo.write(position)

參數

servoServo 型別的變數。

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.