Based on your description, the program needs to know only the new target setting and the current position. That means you need two variables. Algorithmically, it would look as follows (written in C-like pseudo-code):
// initialize global variables (might need float instead of int)
int target_pos = 0;
int current_pos = 0;
void setup() {
// add code to set up pin IO mode, prepare communication with the sensor...
}
// function to read the sensor
int ReadSensorFunc(void) {
int reading = 0; // local variable to store sensor reading
reading = ...; // add code to read sensor
return reading;
}
// function to adjust the motor position
void AdjustStepMotorFunc(void) {
// add code to to adjust the stepper to (target_pos-current_pos);
}
void loop() { // repeat forever
target = ReadSensorFunction() // call sensor read function
AdjustStepMotorFunc() // call position adjustment function
current_pos = target_pos // update current position
// add code to delay for 10 minutes
}
This code initializes the position as zero. In case it's not zero when the controller is turned on, you'll need additional code in setup()
to assign current_pos
the correct value based on user input.