read()

描述

讀取伺服機目前角度。

語法


servo.read()

參數

servoServo 型別的變數。

回傳

伺服機目前的角度(型別為 double 浮點數),如果伺服機尚未出力,回傳值為 0.0。(單位:度)

範例

#include <Servo86.h> 

Servo myservo;
double position;

void setup() 
{ 
  myservo.attach(9);
  myservo.write(90.0);  // 讓伺服機轉到 90 度
  delay(100); // 延遲 100 毫秒
  position = myservo.read(); // 讀取目前角度
  Serial.println(position);
} 

void loop() {} 

See also

write()
writeMicroseconds()
readMicroseconds()


函式庫參考主頁面

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.