Coding a Servo for a PS2 Analog Stick

I have a good code I found on youtube. I would like to change some things but do not know how.
The servos start at 0. When the analog sticks are pushed it moves the servos. When the analog sticks are released the servos go back to 0. I would like the servos to not go to 0 when the analog sticks are released.

Here is the code.

#include <Servo.h>
const int SERVOX=9;                        //Servo X-axis on Pin 9
const int SERVOY=10;                      //Servo Y-axis on Pin 10
const int POTX=0;                        //POT on Analog Pin 0
const int POTY=1;                        //POTY on Analog Pin 1
Servo myServox;
Servo myServoy;
int valX = 0;                            //for storing the reading from the POTX     
int valY = 0;                            //for storing the reading from the POTY
void setup() 
{
  myServox.attach(SERVOX);
  myServoy.attach(SERVOY);
}
void loop()
{
    valX = analogRead(POTX);              //Read Pot
    valX = map(valX, 0, 1023, 0, 170);    //scale it to servo range
    myServox.write(valX);                 //sets the servo
    delay(15);                          //waits for the servo
    valY = analogRead(POTY);              //Read Pot
    valY = map(valY, 0, 1023, 0, 170);    //scale it to servo range
    myServoy.write(valY);                 //sets the servo
    delay(15);                          //waits for the servo
}

I appreciate any knowledge you can give me.

I would like the servos to not go to 0 when the analog sticks are released.

How is the Arduino or server supposed to know when the stick is moving because you are pushing or pulling it as opposed to the spring pulling it back to center?

When you can answer that question, you can easily implement the action that you want.

PaulS:
How is the Arduino or server supposed to know when the stick is moving because you are pushing or pulling it as opposed to the spring pulling it back to center?
When you can answer that question, you can easily implement the action that you want.

It's set like a potentiometer. That is why the servo goes to 0 when the stick does. I can't figure out what part of the code that controls that.

I can't figure out what part of the code that controls that

  valX = analogRead(POTX);              //Read Pot
  valX = map(valX, 0, 1023, 0, 170);    //scale it to servo range
  myServox.write(valX);                 //sets the servo

But can you answer Paul's question ?

I do not know the answer to Paul's question. Obviously because I'm asking for that exact answer. It is not "easy" for everyone.

See reply #3
Do you understand how those 3 lines of code read the pot and move the servo ?

Lets say you push your lever right. Then the servo moves one way. Fine, now you let the stick go back to the center and you want the servo to just stay where it is? What happens when you push the stick right again? Does the servo move more? What if you move left? Does it then go back or just sit like when it goes back to zero?

This is the first thing to sort out. YOUR thinking about exactly what you want it to do. You need to cover all the cases. THEN, the coding will be easy peasy. Your issue isn't the coding, your issue is sorting out what you really want.

Tell us exactly what you want it to do.

-jim lee