Mapping the centred output of a sensor according to another sensor


I am getting to the point in life when I regret not paying more attention in the maths class and I hope I can sincerely ask for help with how to do a bit of maths in Arduino.

I am using a hall effect thumb-wheel with a centre on 2.5volts and a minimum of 0.5 volts and maximum of 4.5volts to give a signal to a motor controller.

The problem I encounter is that with the full range of output the motor controller will go to full speed which is a bit scary as the travel is only 45degrees in each direction.

Planned solution is to use an arduino to read both the hall effect thumb-wheel and a potentiometer in order to re-map the output of the thumb-wheel to values lower/higher than the original while keeping the center value when it is centered.

There are three situations,

1- when thumb-wheel output is 2.5volts then the output needs to be equivalent to 2.5volts.

2- when thumb-wheel output is over 2.5 volts, I need to remap the output to a maximum value determined by the potentiometer input while still staying over 2.5 volts

3-then thumb-wheel ouput is under 2.5 volts , i need to remap the output to a minimum value determined by the potentiometer reading while staying under 2.5volts.

I imagine there is a solution to this but i hit a block searching for it.

Any help will be greatly appreciated!

I need to remap the output to a maximum value

It is not clear what you mean by "remap", please give an example.

Consider using the function constrain().

So you are using an analog input and you get about 512 when the wheel is not being pushed. When you push forward to the forward stop you get about 921 (90% of 1024) and when you pull back to the backward stop you get about 102 (10% of 1024). You want the PWM output to be about 128 (2.5V) when the input is 512 and reduce the forward range from 90% of full scale to… 70%? That would be about 178. You still want the backward travel to reach 10% (about 25).

int input = analogRead(InputPin);
byte PWM;
if (input == 512)
  PWM = 128;
else if (input < 512)
   PWM = input / 4;  // equivalent to PWM = map(input, 0, 512, 0, 128);
  PWM = map(input, 512, 1024, 128, 198);
analogWrite(OutputPin, PWM);

Note: This produces PWM output. You will need a low-pass filter to turn the on/off signal to an analog voltage.