Need Help Controlling Continuous Rotation Servos With a Joystick

I’m having some problems getting two continuous servos (Parallax 900-00008) to work via an analog joystick (parallax 27800). I can manage to get the servos to move and change directions, however, when the joystick is not being touched they continue to move. Also, to get the servos to both go clockwise I have to move the joystick diagonally to the upper right. Any way of fixing these problems?

Here is the code:

#include <Servo.h>

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

int servoVal = (90 ); // 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() {

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

Serial.begin(9600);

}

void loop() {

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);

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

myservo1.write(servoVal);

delay(15);

}

You will need to use some “if” or other conditional logic statements to change the behavior of the program.

Print out the joystick values so you know what is happening when you move it.

So something like this?

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)

if ( servoVal>85 && servoVal <95)
{
myservo2.write(1500);
}
else
{
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, 0, 180); // scale it to use it with the servo (result between 70 and 180)

if ( analogRead>85 && analogRead<95)
{
myservo1.write(1500);
}
else
{
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 ("----------------");
}

Please read "how to use the forum" and edit your posts to use code tags.