setInputPolarity()
描述
設定 A、B、Z 針腳的信號極性。例如:Pulse/DIR 模式下,設定 A 腳極性為 LOW
,代表硬體會將 A 腳的低電位視為 HIGH,高電位視為 LOW。
此函式只可在 Pulse/DIR、CW/CCW、A/B Pulse 工作模式下使用。
語法
Enc0.setInputPolarity(polA, polB, polZ)
Enc1.setInputPolarity(polA, polB, polZ)
Enc2.setInputPolarity(polA, polB, polZ)
Enc3.setInputPolarity(polA, polB, polZ)
參數
Enc0、Enc1、Enc2、Enc3
:分別對應 ENC0、ENC1、ENC2、ENC3 編碼器介面。
polA
:值為 HIGH
或 LOW
。輸入 HIGH
,代表將 A 腳的高電位視為 HIGH,低電位視為 LOW。輸入 LOW
,代表將 A 腳的高電位視為 LOW,低電位視為 HIGH。
polB
:值為 HIGH
或 LOW
。輸入 HIGH
,代表將 B 腳的高電位視為 HIGH,低電位視為 LOW。輸入 LOW
,代表將 B 腳的高電位視為 LOW,低電位視為 HIGH。
polZ
:值為 HIGH
或 LOW
。輸入 HIGH
,代表將 Z 腳的高電位視為 HIGH,低電位視為 LOW。輸入 LOW
,代表將 Z 腳的高電位視為 LOW,低電位視為 HIGH。
回傳
無回傳值
範例
#include <Encoder.h> void setup() { Serial.begin(9600); Enc0.begin(MODE_AB_PHASE); Enc0.setInputPolarity(HIGH, HIGH, LOW); // 設定 pin Z 的極性為相反:高電位視為 LOW,低電位視為 HIGH } void loop() { Serial.println(Enc0.read()); delay(100); }
See also
- begin()
- setIndexReset()
- 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.