Servos movement

I am working on a project with my arduino uno that uses two standard parallax servos and a thumbstick to make a robotic camera arm, 1 servo moves Left/Right the other Up/Down. With the code that i am using right now the servos just move back to their zero position. i would like for them to move to a position and stay there. Any help will help!

Here is the code that i am using:

CODE:

#include <Servo.h>

const int servo1 = 3; // first servo
const int servo2 = 10; // second servo
const int joyH = 3; // L/R Parallax Thumbstick
const int joyV = 4; // U/D Parallax Thumbstick

int servoVal; // variable to read the value from the analog pin

Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo

void setup() {

// Servo
myservo1.attach(servo1); // attaches the servo
myservo2.attach(servo2); // attaches the servo

// Inizialize Serial
Serial.begin(9600);
}

void loop(){

// Display Joystick values using the serial monitor
outputJoystick();

// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyH);
servoVal = map(servoVal, 0, 1023, 0, 180); // scale it to use it with the servo (result between 0 and 180)

myservo2.write(servoVal); // sets the servo position according to the scaled value

// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyV);
servoVal = map(servoVal, 0, 1023, 70, 180); // scale it to use it with the servo (result between 70 and 180)

myservo1.write(servoVal); // sets the servo position according to the scaled value

delay(15); // waits for the servo to get there

}

/**

  • Display joystick values
    */
    void outputJoystick(){

Serial.print(analogRead(joyH));
Serial.print ("---");
Serial.print(analogRead(joyV));
Serial.println ("----------------");
}

Is your issue the fact that the servos go back to their start position when you center the joystick?

that is correct. I am wanting them to move only with the joystick movement and not return back to the center. this is my very first time to work with the arduino and programming and i am lost.

You could use a conditional button "if" statement where if a button is pressed, then the joystick function would be entered. You might be able to remove the springs in the joystick such that the stick does not spring return.

If you imagine that the joystick can move right or left from the central position (the same logic will apply to forwards and backwards) ...

You should be able to write your program so the servo will move left (say) when you push the stick right of centre but will not move right until you move the stick left of centre.

In crude pseudo code it should be something like this

if position < centre move servo right
if position > centre move servo left

Unlike your present code you will not be able to directly translate the joystick position into a servo position.

...R