How i can put together 2 codes

Hello guys,

can please someone help me to integrate this code:

int in1 = 7;
void setup() {
  pinMode(in1, OUTPUT);
  digitalWrite(in1, HIGH);
}
void loop() {
  digitalWrite(in1, LOW);
  delay(3000);
  digitalWrite(in1, HIGH);
  delay(3000);
}

into the main code ?

#include <Servo.h>

Servo servoLeft;          // Definiere linken Servo
Servo servoRight;         // Definiere rechten Servo

void setup() { 
  servoLeft.attach(44);  // Setzt linken Servo auf digital pin 44
  servoRight.attach(22);  // Setzt rechten Servo auf digital pin 22
} 

void loop() {            // Loop für den Bewegungstest
  forward();             // Bsp: Bewege Vorwärts
  delay(2000);           // Waete 2000 millisekunden (2 Sek)
  reverse();
  delay(2000);
  turnRight();
  delay(2000);
  turnLeft();
  delay(2000);
  stopRobot();
  delay(2000);
}

// Bewegungs Routine für Vorwärts, Rückwärts, Drehungen und STOP
void forward() {
  servoLeft.write(0);
  servoRight.write(180);
}

void reverse() {
  servoLeft.write(180);
  servoRight.write(0);
}

void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}
void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
}

void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}

Thanks

Hi there!

All you have to do is copy the commands from one code portion into the same area as the other.

And to discover delay() is giving you trouble... Start rethinking the whole program at once, but this time without delay(). Really the second chapter in any Arduino book should be called "And now never ever use delay() again". Have a look at Blink without delay.

The quick and dirty way is to rename setup() and loop() in one sketch to setup1() and loop1() and in the other to setup2() and loop2(). Then add this bit:

void setup() {
    setup1();
    setup2();
}

void loop() {
    loop1();
    loop2();
}