directionRead()

描述

取得旋轉編碼器的旋轉方向,或是光學尺的移動方向。

注意:從 86Duino Coding 105 版本以後才能使用這個函式,並且只可在 Pulse/DIR、CW/CCW、A/B Pulse 工作模式下使用。

語法


Enc0.directionRead()
Enc1.directionRead()
Enc2.directionRead()
Enc3.directionRead()

參數

回傳

1:正轉(即計數器的值正在遞增)
-1:反轉(即內部計數器的值正在遞減)

範例

#include "Encoder.h"

void setup() {
  Serial.begin(9600);
  Enc0.begin(MODE_AB_PHASE);
}

void loop() {
  Serial.print("count = ");
  Serial.print(Enc0.read()); // 讀取編碼器的計數值
  Serial.print(" ");
  Serial.print("dir = ");
  Serial.print(Enc0.directionRead()); // 印出旋轉或移動的方向
  
  delay(100);
}


函式庫參考主頁面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.