igorantolic / ai-esp32-rotary-encoder

Easy implement rotary encoder to your application using microcontroler like ESP32
GNU General Public License v2.0
284 stars 70 forks source link

areEncoderPinsPulldownforEsp32=false does not enable PULLUP on esp32 #68

Closed kr4fty closed 7 months ago

kr4fty commented 11 months ago

Hello, I am working on an esp32 WROOM board. I need to use my rotary encoder, with center pin connected to GND, so each pin should be configured with PULLUP resistor instead of PULDOWN.

I see that it would be vast with:

encoder.areEncoderPinsPulldownforEsp32=false;

to enable PULLUP resistors instead of PULLDOWN resistors, but it does nothing. When I look in the library, the AiEsp32RotaryEncoder.cppfile I see that the constructor is in charge of setting the PULLUP or PULLDOWN resistors

AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t encoder_APin, uint8_t encoder_BPin, int encoder_ButtonPin, int encoder_VccPin, uint8_t encoderSteps)
{
    ......

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

The question is, shouldn't this be inside the AiEsp32RotaryEncoder::begin() function? Because otherwise it does not produce any effect since the configuration of the resistors is done in the constructor.

Sorry if I'm missing something

Fragment of my program:

#include <AiEsp32RotaryEncoder.h>
.....

AiEsp32RotaryEncoder encoder = AiEsp32RotaryEncoder(ENCODER_PIN_A, ENCODER_PIN_B, BUTTON, ENCODER_VCC_PIN, ENCODER_STEPS);
void IRAM_ATTR readEncoderISR(){
    encoder.readEncoder_ISR();
}
....
void setup() {
....
  encoder.areEncoderPinsPulldownforEsp32=false;
  encoder.begin();
  encoder.setup(readEncoderISR);
  bool circleValues = true;
  encoder.setBoundaries(0, 300, circleValues)
  encoder.setAcceleration(250); 
  encoder.setEncoderValue(encoderCounter);
}
igorantolic commented 7 months ago

optional parameter is now in constructor