Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added constructor argument to choose pinMode for encoder pins #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/AiEsp32RotaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void IRAM_ATTR AiEsp32RotaryEncoder::readButton_ISR()
#endif
}

AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t encoder_APin, uint8_t encoder_BPin, int encoder_ButtonPin, int encoder_VccPin, uint8_t encoderSteps)
AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t encoder_APin, uint8_t encoder_BPin, int encoder_ButtonPin, int encoder_VccPin, uint8_t encoderSteps, bool pullUp)
{
this->old_AB = 0;

Expand All @@ -190,11 +190,11 @@ AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t encoder_APin, uint8_t encoder
this->encoderSteps = encoderSteps;

#if defined(ESP8266)
pinMode(this->encoderAPin, INPUT_PULLUP);
pinMode(this->encoderBPin, INPUT_PULLUP);
pinMode(this->encoderAPin, pullUp ? INPUT_PULLUP : INPUT_PULLDOWN);
pinMode(this->encoderBPin, pullUp ? INPUT_PULLUP : INPUT_PULLDOWN);
#else
pinMode(this->encoderAPin, (areEncoderPinsPulldownforEsp32? INPUT_PULLDOWN:INPUT_PULLUP));
pinMode(this->encoderBPin, (areEncoderPinsPulldownforEsp32? INPUT_PULLDOWN:INPUT_PULLUP));
pinMode(this->encoderAPin, pullUp ? INPUT_PULLUP : INPUT_PULLDOWN);
pinMode(this->encoderBPin, pullUp ? INPUT_PULLUP : INPUT_PULLDOWN);
#endif
}

Expand Down
11 changes: 9 additions & 2 deletions src/AiEsp32RotaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#define AIESP32ROTARYENCODER_DEFAULT_VCC_PIN -1
#define AIESP32ROTARYENCODER_DEFAULT_STEPS 2

#if defined(ESP8266)
#define AIESP32ROTARYENCODER_DEFAULT_PINMODE_PULLUP true
#else
#define AIESP32ROTARYENCODER_DEFAULT_PINMODE_PULLUP false
#endif

typedef enum
{
BUT_DOWN = 0,
Expand Down Expand Up @@ -69,11 +75,12 @@ class AiEsp32RotaryEncoder
uint8_t encoderBPin = AIESP32ROTARYENCODER_DEFAULT_B_PIN,
int encoderButtonPin = AIESP32ROTARYENCODER_DEFAULT_BUT_PIN,
int encoderVccPin = AIESP32ROTARYENCODER_DEFAULT_VCC_PIN,
uint8_t encoderSteps = AIESP32ROTARYENCODER_DEFAULT_STEPS);
uint8_t encoderSteps = AIESP32ROTARYENCODER_DEFAULT_STEPS,
bool pullUp = AIESP32ROTARYENCODER_DEFAULT_PINMODE_PULLUP
);
void setBoundaries(long minValue = -100, long maxValue = 100, bool circleValues = false);
int correctionOffset=2;
bool isButtonPulldown = false;
bool areEncoderPinsPulldownforEsp32 = true;
#if defined(ESP8266)
ICACHE_RAM_ATTR void readEncoder_ISR();
ICACHE_RAM_ATTR void readButton_ISR();
Expand Down