My cheap $3 5 pin rotary encoder breakout usually works by incrementing once per click/turn. Basic stuff. Added it to a code which also included a 4067 multiplexer reading analog potentiometers. It began behaving as if it's not reading the encoder sensors in sync, causing erratic things like getting stuck between values, sometimes going the opposite direction, and only really working when I turn it incredibly slowly, if even.
Meanwhile, the potentiometers attached to the multiplexer work fine.
The section of the code that seems to be causing the trouble is for the multiplexer output pins. When I comment it out, independent of the multiplexer's analog pin for debugging purposes, the encoder goes back to normal behavior. The pins on the board were close so I moved them across them further away, but the lag persists still. You'll see in the code below, the mux pins are in a for loop which continues to the analog read, but the encoder still works with the analog read portion of the loop left in.
is there a way to separate the two in the code so that the encoder is unaffected by the mux pins? Here's the portion of the code that I commented out, which made the encoder work properly again:
for (int i = 0; i < 16; i++) {
int channel = i;
digitalWrite(muxPin0, bitRead(channel, 0));
digitalWrite(muxPin1, bitRead(channel, 1));
digitalWrite(muxPin2, bitRead(channel, 2));
digitalWrite(muxPin3, bitRead(channel, 3));