Control DC motor with encoder using serial monitor

Hello everybody:

Well, my problem is that I'm trying to control the movement of a DC motor, specifically a Maxon A- max 22 model 110164 and it also comes with a encoder which is 110778, the pulse generator is 16 pulse/rev.
I achieved to track the movement of the motor using a different controller to feed the motor and an Arduino Mega to catch the encoder signals A and B.
Now, I'm trying to combine all in only one code, so I was thinking in using the serial monitor in order to input the number of revolutions that I want the motor does, so the code will transform automatically using "map" to relate the revolutions with the number of pulses that catch from the channels A and B of the encoder.

So my problem is how can I do that, I'm using interruptions for both channels, so I don't have problems with getting the number of pulses, i.e. I can track the motor; but I can't achieve that the motor moves if I send a specif number of revolutions because I don't know how to use the counter of the interruptions to put it on an "if - else" or maybe "while" loop, do you have any suggestions.

The motor has 6 wires itself, 2 for DC motor, 2 to feed the encoder and the last 2 are the channels of the encoder.

So, basically what I need is to put a specific number of revolutions in the serial monitor and the motor should move and then stop waiting for another command.

Another problem that I had is when I close the serial monitor and open again after some seconds, the counter of the encoder is reset so it starts again in zero, how can I achieve that the counter starts working immediately after being run the code

Please Help me, I need some suggestions or code examples to control DC with encoder !

I'm also using L298N to control the DC motor

Welcome to the forums.

You will get more help if you post the code and circuit diagrams you have already (use the code tags </>).

Dont try to solve it all at once, break the problem down into small steps. The examples that ship with the arduino IDE are a good place to start in learning to code.