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:值为 HIGHLOW。输入 HIGH,代表将 A 脚的高电位视为 HIGH,低电位视为 LOW。输入 LOW,代表将 A 脚的高电位视为 LOW,低电位视为 HIGH。

polB:值为 HIGHLOW。输入 HIGH,代表将 B 脚的高电位视为 HIGH,低电位视为 LOW。输入 LOW,代表将 B 脚的高电位视为 LOW,低电位视为 HIGH。

polZ:值为 HIGHLOW。输入 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.