Zero - Max Value with two Potentiometers

I have revised the code a bit, but still not like the way that i want :frowning:

// Analog Sensor is installed in rotational axis joint of Arm
// The Arm shall move to Zero Point and set to 0 with Minimum Potentiometer (whatever value get from Analog Sensor)
// The Arm shall move to Maximum Point and set to Maximum Value with Maximum Potentiometer (whatever value get from Analog Sensor)
// Maximum Value shown is in centimeters
// System Reset
// Measure with Angle Sensor
// Maximum Measurement is 500 centimeters

const int minPin = A0;      // Potentiometer for Zero Point
const int maxPin = A1;      // Potentiometer for Max Point
const int sensorPin = A2;   // Analog Sensor 0..5V for Angle Measurement (0 V = 0 Degree...5 V = 359 Degree)

int minValue = 0;           // Sets Minimum Value
int maxValue = 0;           // Sets Maximum Value
int sensorValue = 0;        // Sensor Value

int minOffset = 0;          // Minimum Measurement Value 0
int maxOffset = 0;          // Maximum Measurement Value
int calculated = 0;         // Calculated Value


void setup() {
  Serial.begin(9600);
}

void loop() {
  minValue = analogRead(minPin);                             // Read Potentiometer for Minimum
  maxValue = analogRead(maxPin);                             // Read Potentiometer for Maximum
  minValue = map(minValue, 0, 1023, 0, 400);
  maxValue = map(maxValue, 0, 1023, 0, 400);
  Serial.print("Min: ");
  Serial.println(minValue);
  Serial.print("Max: ");
  Serial.println(maxValue);
  // sensorValue = map(sensorValue, 0, 1023, 0, (maxValue - minValue));
  // minOffset = minValue;
  maxOffset = maxValue - minValue;
  sensorValue = analogRead(sensorPin);                       // Read Analog Angle Sensor
  sensorValue = constrain(sensorValue, 0, maxOffset);
  Serial.print("Sensor: ");
  Serial.println(sensorValue);
  Serial.println();
  delay(500);
}

In above example, i set minimum potentiometer to value 100, and the maximum potentiometer to value 400, so i can measure between 0 to 300 accordingly, and after some point it never measures over 300 as i limit the value.

The limit on end seems work but not for the start :frowning: