I have built a little robot that moves along an x and y axis with 2 servos, It is controlled with a thumbstick salvaged from an Xbox 360 controller. The code below allows it to work fine but it does not allow me to control the speed of the servos. If I understand correctly the .write() function is replaced with .slowmove() ie.
example
myServo1.write(servoVal);
// would be replaced with
myServo1.slowmove(50,servoVal);
but when I do that my servos lock to one direction and are no longer controllable with the thumbstick.... any Idea what I am doing wrong? Here is my code. Ive commented out the slowmove.() functions
#include <VarSpeedServo.h>
const int servo1 = 5; // first servo
const int servo2 = 7; // second servo
const int joyH = 1; // L/R Parallax Thumbstick
const int joyV = 2; // U/D Parallax Thumbstick
int servoVal; // variable to read the value from the analog pin
VarSpeedServo myservo1; // create servo object to control a servo
VarSpeedServo myservo2; // create servo object to control a servo
void setup() {
// Servo
myservo1.attach(5,0,255); // attaches the servo
myservo2.attach(7,0,180); // 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
//myservo2.slowmove(150,servoVal)
// 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
//myservo2.slowmove(150,servoVal)
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 ("----------------");
}