Making servos run at the same time

How do I make the servos run at the same time in this code?

#include <Servo.h> //Library van Servo

#include <Adafruit_GFX.h> //Libraries van OLED display
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4 //Instellen van OLED display
Adafruit_SSD1306 display(OLED_RESET);

Servo myservo;
Servo myservo2;

int pos = 0; //Startpositie van Servo
int pos2 = 90;

void setup() {
myservo.attach(4); //Plaatsing van de Servos
myservo2.attach(3);
}

void loop() {

for (pos = 0; pos <= 90; pos += 1) { //Draai van 0 tot 90 graden met stappen van 1 graad
myservo.write(pos);
millis(50);
}
for (pos2 = 90; pos2 >= 0; pos2 -= 1) {
myservo2.write(pos2);
millis(50);
}
for (pos = 90; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
for (pos2 = 0; pos2 <= 90; pos2 += 1) {
myservo2.write(pos2);
delay(15);
}

}

How do I make the servos run at the same time in this code?

for (pos = 90; pos >= 0; pos -= 1) 
  {
    myservo.write(pos);
    myservo2.write(pos);
    //millis(50);  //this line is wrong
  }

That is not how you use millis()
See Using millis() for timing. A beginners guide

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Change from two loops to one:

 for (pos = 0; pos <= 90; pos += 1) {                                                           //Draai van 0 tot 90 graden met stappen van 1 graad
    myservo.write(pos);
    delay(50);
  }
  for (pos2 = 90; pos2 >= 0; pos2 -= 1) {
    myservo2.write(pos2);
    delay(50);
  }

becomes:

 for (pos = 0; pos <= 90; pos += 1) {                                                           //Draai van 0 tot 90 graden met stappen van 1 graad
    myservo.write(pos);
    myservo2.write(90 - pos);
    delay(50);
  }