please help i have no idea what im doing

so here’s what’s happening: I am trying to make my robot arm servos move through two joysticks, which I have successfully done through simple coding…

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;

int joyX = 0;
int joyY = 1;
int joyX1 = 3;

int joyVal;

void setup()
{
servo1.attach(6);
servo2.attach(4);
servo3.attach(5);
}

void loop()
{
joyVal = analogRead(joyX);
joyVal = map(joyVal, 0, 1023, 0, 100);
servo1.write(joyVal);

joyVal = analogRead(joyY);
joyVal = map(joyVal, 0, 1023, 60, 100);
servo2.write(joyVal);

joyVal = analogRead(joyX1);
joyVal = map (joyVal, 0, 1023, 0, 100);
servo3.write(joyVal);

delay(15);
}

and this causes the servos to follow the motion of the joystick, so when the joystick return to its center position, the servo does as well. What I want and need help with is for the joystick to move the servo, but leave it in that position even when the joystick returns to its center point. I hope that makes sense.

Have a look at this demo

...R

okay so I tried that and it works great! its exactly what I wanted thank you so much! now I just need to know how to include my other servos in the new code like this…

// Simple demonstration to show how to move a servo with a joystick
//   or potentiometer so that the servo does not lose its position
//   when the joystick centres itself

#include <Servo.h>

Servo myServo1;
Servo myServo2;
Servo myServo3;

void setup()
{
  myServo1.attach(6);
  myServo2.attach(4);
  myServo3.attach(5);
}

int servoPos = 90;
int servoMax = 130;
int servoMin = 45;
int servoMove = 3;  // number of degrees per movement

byte potPin0 = A0;
byte potPin1 = A1;   // center pin of joystick or potentiometer connected here
byte potPin2 = A2;
byte potPin3 = A3;

int potValue = 0;
int potCentre = 512; // adjust to suit your joystick
int potDeadRange = 50; // movements by this much either side of centre are ignored

unsigned long curMillis;
unsigned long readIntervalMillis = 100;
unsigned long lastReadMillis;

Serial.begin(9600);
Serial.println("Starting JoystickServo.ino");                                        HERE!!

myServo1.attach(servoPin0);
myServo2.attach(servoPin1);
myServo3.attach(servoPin2);
myServo1.write(servoPos);
myServo2.write(servoPos);
myServo3.write(servoPos);
}

void loop() {
  curMillis = millis();
  readJoystick();
  moveServo();
  showPosition();
}

void readJoystick() {
  // check the time
  if (curMillis - lastReadMillis >= readIntervalMillis) {
    lastReadMillis += readIntervalMillis;
    // read the joystick
    potValue = analogRead(potPin);
    // figure if a move is required
    if (potValue > potCentre + potDeadRange) {
      servoPos += servoMove;
    }
    if (potValue < potCentre - potDeadRange) {
      servoPos -= servoMove;
    }
    // check that the values are within limits
    if (servoPos > servoMax) {
      servoPos = servoMax;
    }
    if (servoPos < servoMin) {
      servoPos = servoMin;
    }
  }
}

void moveServo() {
  myServo.write(servoPos);
}

void showPosition() {
  Serial.print("PotValue ");
  Serial.print(potValue);
  Serial.print("   ServoPos ");
  Serial.println(servoPos);
}

then I got the error message : “exit status 1
‘Serial’ does not name a type”(where code line says HERE!! next to it)
any ideas?

Moderator edit: [code][/code] tags added. (Nick Gammon)

  Serial.begin(9600);

That code isn't in a function.

Please remember to use code tags when posting code.

void setup()

{
  myServo1.attach(6);
  myServo2.attach(4);
  myServo3.attach(5);
}  // <-------------- here

I put your code into code tags for you.

Please use code tags.

Read this before posting a programming question

How to use this forum

You closed your setup function prematurely (where I put “here”).

Also it looks like you have put variables in setup (or they would be if you got rid of that brace) which should really be global.

Do some C or C++ tutorials. Code has a certain structure to it, you can’t just bang things any old place.