setDigitalFilter()

描述

開啟 A、B、Z 針腳的數位濾波功能,可用於濾除指定寬度以下的雜訊。

注意:在 PWM 脈波捕捉模式下,此函式只能在呼叫 Encoder 函式庫內的 attachInterrupt()pulseIn()pulseInNanoseconds 前使用。

語法


Enc0.setDigitalFilter(val)
Enc1.setDigitalFilter(val)
Enc2.setDigitalFilter(val)
Enc3.setDigitalFilter(val)

參數

Enc0、Enc1、Enc2、Enc3:分別對應 ENC0、ENC1、ENC2、ENC3 編碼器介面。

val:要濾除的雜訊最大寬度。(unsigned long 型別,單位:10 ns)

回傳

無回傳值

範例

#include <Encoder.h>
 
void setup() {
  Serial.begin(9600);
  Enc0.begin(MODE_AB_PHASE);
  Enc0.setDigitalFilter(20L); // 濾除 200ns 以下的雜訊
}
 
void loop() {
  Serial.println(Enc0.read());
  delay(100);
}

See also

begin()
read()


函式庫參考主頁面

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.