read poti and accordingling adjust position.

hello,
need to create code that reads two pairs of sensors/values. one is potentiometers (in a way rotary encoders..) mounted within a diy cardan joint, turns ~150-160 degrees and another is (for testing another pot) or incoming data from an mpu6050.
this is for two axis. it should compare the incoming data with the data from the local pot and if different turn on the motor switch relay for motor direction and stop the motor if the position of x and y axis is reached. the motors drive two threaded bars which move a rod x/y wise mounted on the cardan joint/food...and very important don't stop the loop from receiving continous data (virtual wire) from the mpu6050 ypr...
i am not very experienced in c++ so i need to learn howto correctly setup the "if..." or "while" ...whatever method is needed using millis function. right it sort of messes up everything if the motors start.
could someone point me into the right direction?
thanks in advance.
attached is the fragment/section of the projectcode where i am trying to achieve this

posXY.ino (697 Bytes)