Enable Rotary Encoder Support
masterThe library supports rotary encoders, but this feature must be enabled manually in the library header.
- Open
PCF8574.hand uncomment#define PCF8574_ENCODER_SUPPORTor#define PCF8574_ENCODER_SUPPORT_OPTIMIZED. - Use
pcf8574.encoder(pinA, pinB)to initialize the encoder pins. - Use
pcf8574.getEncoderValue()to retrieve the current position. - Use
pcf8574.setEncoderValue(value)to reset the position.
// In PCF8574.h, uncomment:
// #define PCF8574_ENCODER_SUPPORT
PCF8574 pcf8574(0x20);
const uint8_t ENCODER_A = P0;
const uint8_t ENCODER_B = P1;
void setup() {
pcf8574.begin();
pcf8574.encoder(ENCODER_A, ENCODER_B);
pcf8574.setEncoderValue(0);
}
void loop() {
long val = pcf8574.getEncoderValue();
}