Based on Oleg Mazurov's code for rotary encoder interrupt service routines for AVR micros here: https://chome.nerpa.tech/mcu/reading-rotary-encoder-on-arduino/
and using interrupts: https://chome.nerpa.tech/mcu/rotary-encoder-interrupt-service-routine-for-avr-micros/
This example does not use the port read method. Tested with Nano and ESP32. Note that both encoder A and B pins must be connected to interrupt enabled pins