How to make servos move at the same time with VarSpeedServo.h

My project is a robotic arm. I've been wanting to make the arm's movements more efficient by making the joints move at the same time instead of one at a time. However, I can't figure out how to do that with VarSpeedServo.

Below is the current code. It's a bit long and messy as it was just to test out VarSpeedServo.h
The function of the code is to pick and place an object.

//include custom library to control servos
#include <VarSpeedServo.h>
//Create servo variable
VarSpeedServo servoBase;
VarSpeedServo servoArm1;
VarSpeedServo servoArm2;
VarSpeedServo servoArmGrip;
VarSpeedServo servoGrip;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600); // set the serial monitor data rate

                    // assign pins to each servo motor
servoBase.attach(3);
servoArm1.attach(5);
servoArm2.attach(6);
servoArmGrip.attach(9);
servoGrip.attach(10);
Serial.println("output initialized");

armDefault();

//SPEED SETTINGS

const int SPEED1 = 15; //speed one is default speed.
const int SPEED2 = 30; //speed faster is slower and is for movements that don't require more precision.
 
}

          //CREATE FUNCTIONS
          
void armDefault() // sets the arm to the default position
{
const int SPEED1 = 15; //speed one is default speed.
//zero out the base motor
servoBase.write(0,SPEED1, true);

//set servo arms to default position

servoArm1.write(120,SPEED1,true);


servoArm2.write(100,SPEED1,true);


servoArmGrip.write(120,SPEED1,true);

delay(100);
servoGrip.attach(10);
servoGrip.write(0);
delay(100);
servoGrip.detach();
}


void armRetract() //arm retract is similiar to default, however it does not include the gripper
{
const int SPEED1 = 15; //speed one is default speed.

servoArm1.write(68,SPEED1, true); // set to 68 instead of 65 as the angle for some reason changes slightly, this is just to account for it.

servoArm2.write(100,SPEED1,true);

servoArm1.write(120,SPEED1,true);
}



void armExtend(int SPEED1, int SPEED2) //this function serves to extend the arm
{

servoArm1.write(65,SPEED2,true); //the servo is set to 65 instead of 90 due to hardware issues. 65 = 90 degrees in this case

servoArm2.write(140,SPEED2,true);

servoArm1.write(30,SPEED1,true);
}

//Claw functions 

void clawClose() // activates servo motor responsible for closing claw
{
delay(200);
servoGrip.attach(10);
servoGrip.write(180);
delay(100);
servoGrip.detach();
}

void clawOpen() //activates servo motor responsible for opening claw
{
delay(100);
servoGrip.attach(10);
servoGrip.write(0);
delay(100);
servoGrip.detach();
}


//Swivel functions

void SWIVEL0()
{
  const int SPEED1 = 15; //speed one is default speed.
  const int SPEED2 = 30; //speed faster is slower and is for movements that don't require more precision.
  servoBase.write(0,SPEED2,true);
}



void SWIVEL90()
{
  const int SPEED1 = 15; //speed one is default speed.
  const int SPEED2 = 30; //speed faster is slower and is for movements that don't require more precision.
  servoBase.write(90,SPEED2,true);
}

void SWIVEL180()
{
  const int SPEED1 = 15; //speed one is default speed.
  const int SPEED2 = 30; //speed faster is slower and is for movements that don't require more precision.
  servoBase.write(180,SPEED2,true);
}


void loop() {
  // put your main code here, to run repeatedly:


delay(500);

SWIVEL180();

delay(500);

armExtend(15, 30); //integers in brackets represent speed

delay(500);

clawClose();

delay(500);

armRetract();

//end block 

delay(500);

SWIVEL90();

//

delay(500);

armExtend(15, 30);

delay(500);

clawOpen();

delay(500);

armRetract();

delay(500);


SWIVEL180();

delay(500);

armExtend(15, 30);

delay(500);

clawClose();

delay(500);

armRetract();


SWIVEL0();

delay(500);

armExtend(15, 30);

delay(500);

clawOpen();

delay(500);

armRetract();

}```

Take a look at the second example here GitHub - netlabtoolkit/VarSpeedServo: Arduino library for servos that extends the standard servo.h library with the ability to set speed, and wait for position to complete

thank you so much, that's exactly what I needed. :slight_smile:

When all else fails RTFM (or the equivalent)