Is it possible to slow a servo through programming?

Hi,

I am making a robot and are using two servos for the eye lid movement, at the moment the servos turn far too fast. They are controlled by a joystick. Is there some code I can use to slow down the servos? I’ve heard that maybe using if operator might work though I don’t know how this would work. Here is the code I have at the moment. I also have another 2 servos being controlled by a joystick these are servo 1, servo 2, joyH and joyV, please just ignore these. Thank you!!!

#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
const int eyejoy = 1;
const int servo3 = 6;
const int servo4 = 5;

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

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

void setup() {

// Servo
myservo1.attach(servo1); // attaches the servo
myservo2.attach(servo2); // attaches the servo
eyeservoTOP.attach(servo3);
eyeservoBOT.attach(servo4);

// 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, 70); // scale it to use it with the servo (result between 0 and 180)
servoVal = constrain(servoVal, 20, 50);

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, 170, 1023, 0, 170); // scale it to use it with the servo (result between 70 and 180)
servoVal = constrain(servoVal, 50, 100);

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

//EYELIDS

eyelidVal = analogRead(eyejoy);
eyelidVal = map(eyelidVal, 0, 1023, 80, 0); // scale it to use it with the servo (result between 0 and 180)
eyeservoTOP.write(eyelidVal);

eyelidVal = analogRead(eyejoy);
eyelidVal = map(eyelidVal, 0, 1023, 0, 80); // scale it to use it with the servo (result between 0 and 180)
eyeservoBOT.write(eyelidVal);

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 ("----------------");
Serial.print(analogRead(eyejoy));
Serial.print ("—");

}

Yes, it is possible to slow a servo through code. Take a little step. Wait. Take a little step. Wait...

The size of the steps, and how long you wait, determine, overall, how fast the servo moves.

The servo sweep example in the Arduino IDE demonstrates what @PaulS mentioned.

...R