setInputPolarity()

Description

Set signal polarity for pin A, B and Z, such as: Under the Pulse/DIR mode, set pin A polarity to LOW, which configure the system to interpret the low voltage condition for pin A as signal HIGH and high voltage condition for the pin as signal LOW.

This function is valid under the Pulse/DIR, CW/CCW and A/B Pulse operating mode.

Syntax


Enc0.setInputPolarity(polA, polB, polZ)
Enc1.setInputPolarity(polA, polB, polZ)
Enc2.setInputPolarity(polA, polB, polZ)
Enc3.setInputPolarity(polA, polB, polZ)

Parameters

Enc0、Enc1、Enc2、Enc3:Corresponding to ENC0, ENC1, ENC2 and ENC3 encoder interfaces.

polA:Set to HIGH or LOW.
When set to HIGH, pin A high voltage condition translate to logic HIGH and low voltage condition translate logic LOW.
When set to LOW, pin A high voltage condition translate to logic LOW and low voltage condition translate to logic HIGH.

polB:Set to輸入 HIGH or LOW.
When set to輸入 HIGH, pin B high voltage condition translate to logic HIGH and low voltage condition translate logic LOW.
When set to LOW, pin B high voltage condition translate to logic LOW and low voltage condition translate to logic HIGH.

polZ:Set to HIGH or LOW.
When set to HIGH, pin Z high voltage condition translate to logic HIGH and low voltage condition translate logic LOW.
When set to LOW, pin Z high voltage condition translate to logic LOW and low voltage condition translate to logic HIGH.

Returns

None

Example

#include <Encoder.h>
 
void setup() {
  Serial.begin(9600);
  Enc0.begin(MODE_AB_PHASE);
  Enc0.setInputPolarity(HIGH, HIGH, LOW); // Set pin Z polarity to the reversed condition:  When the pin is in voltage HIGH condition,it’s translated to logic LOW and when it’s in voltage LOW condition,it’s translated to logic HIGH
}
 
void loop() {
  Serial.println(Enc0.read());
  delay(100);
}

See also

begin()
setIndexReset()
read()


Libraries Reference Home

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.