integration of servo code into my programm

hy,

i need help because I don't know how I could integrate my servo code into my main code.

what must i do, that the servos move after the last LED is turned off?
please help me

here is my main code:

int ledPin = 7;
int tasterPin = 4;

void setup(){
pinMode(ledPin,OUTPUT);
pinMode(tasterPin,INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
}

void loop(){
if (digitalRead(tasterPin)==LOW){
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
}

and here is my servo code:

#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
void setup() {
servoLeft.attach(10); // Set left servo to digital pin 10
servoRight.attach(9); // Set right servo to digital pin 9
}
void loop() { // Loop through motion tests
forward(); // Example: move forward
delay(2000); // Wait 2000 milliseconds (2 seconds)
reverse();
delay(2000);
turnRight();
delay(2000);
turnLeft();
delay(2000);
stopRobot();
delay(2000);
}
// Motion routines for forward, reverse, turns, and 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);
}

Forum software and code are incompatible - the tags and keywords collide. Read this, and edit your post, so we are looking at the same thing.

Just merge the global declarations, the contents of the setup() function and the contents of the loop() function:

#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo

const int ledPin = 7;
const int tasterPin = 4;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(tasterPin, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(8, OUTPUT);
  servoLeft.attach(10); // Set left servo to digital pin 10
  servoRight.attach(9); // Set right servo to digital pin 9
}

void loop() {
  if (digitalRead(tasterPin) == LOW) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    forward(); // Example: move forward
    delay(2000); // Wait 2000 milliseconds (2 seconds)
    reverse();
    delay(2000);
    turnRight();
    delay(2000);
    turnLeft();
    delay(2000);
    stopRobot();
    delay(2000);
  }
}

// Motion routines for forward, reverse, turns, and 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);
}

ChrisTenone, your link doesn't work
pls tell me what i have to do

Thx John,
I'll try it on the weekend (sunday)

kindly regards

Don

Oh, sorry Don. Put the code in code tags, so it will be properly formatted in a monospaced font, and the characters that are also bbcode mark-up, like [ and / do not get misinterpreted by the forum software. It's all in a link called "How to use this forum - please read" that explains how to do that. Here's the link :stuck_out_tongue: :

http://forum.arduino.cc/index.php?topic=148996.0

ChrisTenone:
Oh, sorry Don. Put the code in code tags, so it will be properly formatted in a monospaced font, and the characters that are also bbcode mark-up, like [ and / do not get misinterpreted by the forum software. It's all in a link called "How to use this forum - please read" that explains how to do that. Here's the link :stuck_out_tongue: :

How to use this forum - please read - Website and Forum - Arduino Forum

It would be nice if people use code tags but I also like URL tags. They make links clickable.

http://forum.arduino.cc/index.php?topic=148996.0

Though a link without URL tags beats no link at all.

Edit: I noticed the example of how to link to the "How to . . ." thread included URL tags (though they aren't mentioned elsewhere in the thread).

I'm not suggesting anyone is "wrong" for not using URL tags (though I may secretly harbor such thoughts).

@Dtensta, Sorry for the side track. Make sure and let us know if you're still having trouble.

Hey Duane, I like 'em too! Clickable links are a marvelous invention. Unfortunately when used with 'Copy Link", sometimes (I'm not sure of the exact circumstances) an 'iurl' (rather than a url) link is generated that does not build a correct link. I now see that the 'always works' way to post a link is to go to the page desired for the link, and copy its url from the browser's navigation bar, then paste it between url tags.

I will be more careful to do that in the future. I was indeed guilty of 'tag hipocracy'.

... However, leaving out url tags makes a bit more work for the reader. Leaving out code tags can mangle code by interpreting the text of the code as bbcode. Look through un-tagged code, and you will occasionally see mysterious smilies, or half the code is suddenly in italics or bold.

@ChrisTenone, I always work with my editor in "Source" mode (see the right-most icon, and settings in your Profile) and that problem of iurls goes away.

...R

Thanks Robin, I have adjusted my profile so it's MUCH easier to use now! Y'all won't see another naked url from me again!

(The link is just me practicing, to be sure I've got it right. Note: in this forum, the url tag does NOT want the actual url in quotes.)

thx foir this code,thx for helping, it works pretty fine :slight_smile:
I'd like to show u an example video :

Video Project Apha Status

#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo

const int ledPin = 7;
const int tasterPin = 4;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(tasterPin, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(8, OUTPUT);
  servoLeft.attach(10); // Set left servo to digital pin 10
  servoRight.attach(9); // Set right servo to digital pin 9
}

void loop() {
  if (digitalRead(tasterPin) == LOW) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);              // wait for a second
    digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
    delay(500);              // wait for a second
    forward(); // Example: move forward
    delay(2000); // Wait 2000 milliseconds (2 seconds)
    reverse();
    delay(2000);
    turnRight();
    delay(2000);
    turnLeft();
    delay(2000);
    stopRobot();
    delay(2000);
  }
}

// Motion routines for forward, reverse, turns, and 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);
}