This is a general question. I could provide code if needed, but I think it would be better to explain my problem and see if anyone has a solution.
I have been using Arduino successfully for about 6 months now and have written several useful programs. I am a novice programmer, but have written simple programs in several languages, including machine code (years ago!).
I would like to control the position of two different motors simultaneously with one Arduino Uno. It has two interrupt pins, so can keep track of two rotary encoder pulses. However, there is an issue when trying to position both motors at the same time. I would like to call a motor control function that takes a position and a mode input and depending on the mode, will either drive motor 1 (to a specific position), or motor 2, or both at once with one or the other being a master (for position) while the other simply uses the same duration motor pulses.
In order for the motor control function to work as intended, I need to be able to keep track of the position of one of the two motors depending on the 'mode'. In order to do this, I need to be able to have a while loop that stops based on a variable value (the encoder counter) reaching a limit. But I want this to be able to change which encoder counter is used based on the mode. I thought I could use a single variable (say, 'Counter') to hold one or the other encoder value and use a switch statement at the beginning of the function to have Counter equal either Encoder1 or Encoder2. But realized this will only cause them to be equal at the beginning of the function and will not continue to track as the ISR updates the value.
So (finally) here are my questions:
Is there a way to have two variables constantly stay the same value without having a new assignment statement?
OR, is there another way to write the motor control function?