// Forum: https://forum.arduino.cc/t/how-to-move-2-servos-in-different-directions-with-speed-control/1091643
// This Wokwi project: https://wokwi.com/projects/356962335315431425
#include <Servo.h>
Servo myServo1;
Servo myServo2;
int position = 0;
int delta = +1; // controls direction and speed
void setup()
{
myServo1.attach(5);
myServo2.attach(6);
}
void loop()
{
// Set the new positions of the servo motors.
myServo1.write( position);
myServo2.write( 180 - position);
// Calculate new position.
position += delta;
if( position <= 0 or position >= 180)
delta = -delta;
// Control the speed with the delay, about 5 to 100ms.
delay( 15);
}