I'm building an inverted pendulum. I have two rotary encoders and a 12V DC motor.
Right now when I try to run the DC motor and change one of the rotary encoders, the rotary encoder will not print to the serial monitor. However, when I unplug the DC motor, the rotary encoder works fine, so I think the communication isn't fast enough here or there's something I'm doing wrong (and this is just for one rotary encoder!).
Room for improvement:
Upgrade from an Elegoo Uno board to an actual Arduino Uno board (perhaps something even better).
Change the serial baud rate from 9400 b/s.
Instead of using digitalRead, analogWrite, etc., write code that is more efficient.
Here is a gist of my testing code right now for reference. My question is, how can I get the most out of the Arduino communication? How can I make it be as fast as possible without (or minimal) errors?