Using a mid position pot to control PWM speed of DC motor

Hi Im trying to us a joystick pot that is like the one from a playstation controller

its value is 10k mid position at 5 k. Im only using one of the pots, took the other one out

the issue is that I just want to use a forward push to move the motor and at mid position, starting at 0

dont need reverse but when I reverse past the 0 mid point, I get movement. I only want movement from the 0 mid point, push forward and get to max speed, release, be back at mid point and stop at 0

my map code is as follows

int varX = analogRead(joy1);
varX=map(varX, 512,1023, 0,255);
analogWrite(dcmotor, valX);

Ive tried 1023,512,0, 255 and other patterns but success. Just want mid rest position to be at 0 and throttle up from that.

I cannot see your code. Post the entire sketch. Don't forget to use code tags.

I cannot quite understand what you want. Can you try to explain again? What does the sketch do that differs from what you expect?

void handscontrol() {
int varX = analogRead(joy1);
varX = map(varX, 1023,512, 0,255);

analogWrite(dcmotor, valX);

its just a function that gets called with a button push

so what I want to do is push forward on a joystick, and control the speed of a DC motor by PWM. this PWM part works but the joystick is not controlling the motor like I want

at rest, this joystick is at midrange. right now the motor is at full speed at mid range position. Dont want that, I want it to be off at mid position and then in one push direction only, throttle the motor up to full speed, by PWM. There is no issue with the PWM code, just the joystick code

these playstation or sparkfun joystick 10k pots seem to be at 10k at one extreme, then 5k at mid position then 10k at the other extreme

its not like 0---->5k------->10k

so its difficult to map it

I suspect all you need is something like

if (varX < 512) {
  varX = 512;
}

...R

analogWrite(dcmotor, valX);

Did you mean:
analogWrite(dcmotor, varX); ?