How do I have an LED blink once per loop while operating servos?

#include <Servo.h>
const int x = 250;
Servo motorL;
Servo motorR;
void setup()
{
motorL.attach(4);
motorR.attach(5);
Serial.begin(9600);
}

void forward()
{
motorR.write(93);
motorL.write(80);
delay(100);
motorL.write(250);
motorR.write(5);
}

void back()
{
motorR.write(93);
motorL.write(80);
delay(100);
motorL.write(5);
motorR.write(250);
}

void right()
{
motorL.write(80);
motorR.write(93);
delay(100);
motorL.write(5);
motorR.write(93);
}

void left()
{
motorL.write(80);
motorR.write(93);
delay(100);
motorL.write(80);
motorR.write(250);
}

void stop()
{
motorL.write(80);
motorR.write(93);
delay(100);
}

void LED() {
pinMode(13, OUTPUT);
}

void loop() {
forward();
delay(500);
right();
delay(500);
forward();
delay(500);
back();
delay(1000);
left();
delay(500);
motorL.detach();
motorR.detach();
}

Get rid of the calls to delay ().

And code tags. We love code tags.

Read Demonstration code for several things at the same time

The demonstration code has an error that has been identified by Arduino (not uploading) doesn't seem to work and I'm not sure what's the problem. Is there another way?

It doesn't seem to work

What is the "it" that doesn't seem to work?

sterretje:
Read Demonstration code for several things at the same time

If you're talking about this not working, well 17 minutes isn't really long enough to read and understand the article much less rewrite the code to use the approach.

But that's what you have to do. If it doesn't work then you did it wrong. Post what you did and we will try to help you figure it out.

To add to what @Delta_G has said you are the first person to report a problem with Several Things at a Time and if there really is a problem I would like to know so I can fix it.

...R

nafi04:
The demonstration code has an error that has been identified by Arduino (not uploading) doesn't seem to work and I'm not sure what's the problem. Is there another way?

You need to add a new word to your vocabulary.

Delay is a blocking function. That means the CPU stays inside it and does nothing1 until the delay is over. This is fine if your program is only doing one thing, like moving through a fixed sequence of servo movements, and this is all that you even intend your program to do. The moment you try to do 2 things at irregular intervals (intervals that do not have a common denominator) though, everything falls apart.

delay() is the most abused function in the entire Arduino library. It's so seductive how easy it to use to create a timed sequence of events that people get suckered in and start using it right away, just like this. But it's a trap. delay() is not an easy way to do things. It is a terrible, vile, evil thing and you must train yourself to never use it in loop() or any function that will ever be called by loop ever.2

I exaggerate only slightly. When you try to rewrite this, just pretend delay() doesn't exist, has never existed, and never will exist. I promise that you will be better off doing so.

1 Interrupts excepted, but this doesn't matter to you since at your level of skill they'll just make things worse.
2 Some may dispute this. If you are able to able to make a good case with logic or evidence about how certain uses of delay are beneficial, then you already know the giant, heaping, stinking pile of other uses where it is pure evil and do not need to be told about them.

nafi04:
The demonstration code has an error that has been identified by Arduino (not uploading) doesn't seem to work and I'm not sure what's the problem. Is there another way?

I have successfully tried that example without problem. Sketches not uploading is a known bug that might show after opening a sketch by doubleclicking on .ino-file. Workaround is described here.

http://forum.arduino.cc/index.php?topic=416228.msg2866433#msg2866433

@nafi04: post-editing posts isn't helpful.
Not providing the exact texts of the code you tried and the error(s) you got. . . isn't helpful.

It turns out it was a problem with the board, but it's fixed now. How do I change the "several things at once" code to my advantage?

This might give you some ideas.
Here is a comparison of using: 'blocking code' then 'non blocking code' to do the same thing.

 // program to sequentially turn on and turn off 3 LEDs
 
const byte LED1 = 2;
const byte LED2 = 3;
const byte LED3 = 4;
const byte heartBeat = 13;
 
boolean blockingFlag = true;
 
unsigned long Millis13;
unsigned long lastMillis;
unsigned long wait = 3000;
 
enum States {
  StateStart, State2, State3, State4, State5, State6, State7
};
States mState = StateStart;
 
void setup()
{
  pinMode(heartBeat, OUTPUT);
 
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
 
  delay(3000);
 
} //END of setup()
 
 
void loop()
{
  //**********************************
  //some code to check for blocking sketches
  if (millis() - Millis13 >= 200)
  {
    digitalWrite(heartBeat, !digitalRead(heartBeat)); //toggle D13
    Millis13 = millis(); //re-initalize
  }
 
  //********************************** delay() being used here
  if (blockingFlag == true)
  {
    blockingFlag = false;
    digitalWrite(13, LOW);
 
    blockingMethod();
   }
 
  //********************************** BWD being used here
  if (millis() - lastMillis >= wait)
  {
    nonBlockingMethod();
  }
 
  //Other non blocking code goes here
 
} //END of loop()
 
 
 
 
// ******************* Functions *******************
void blockingMethod()
{
  //LEDs ON
  digitalWrite(LED3, HIGH);    // turn on LED3
  delay(450);                  // wait for 450ms
  digitalWrite(LED2, HIGH);    // turn on LED2
  delay(450);                  // wait for 450ms
  digitalWrite(LED1, HIGH);    // turn on LED1
  delay(3000);                 // wait for 3000ms
 
  //LEDs OFF
  digitalWrite(LED3, LOW);     // turn off LED3
  delay(450);                  // wait for 450ms
  digitalWrite(LED2, LOW);     // turn off LED2
  delay(450);                  // wait for 450ms
  digitalWrite(LED1, LOW);     // turn off LED1
  delay(3000);                 // wait for 3000ms
 
} //END of blockingMethod()
 
 
void nonBlockingMethod()
{
  switch (mState)
  {
    //***************************    //LEDs ON
    case StateStart:
      {
        digitalWrite(LED3, HIGH);    // turn on LED3
        wait = 450;                  // wait for 450ms
        lastMillis = millis();
        mState = State2;
      }
      break;
 
    //***************************
    case State2:
      {
        digitalWrite(LED2, HIGH);    // turn on LED2
        wait = 450;                  // wait for 450ms
        lastMillis = millis();
        mState = State3;
      }
      break;
 
    //***************************
    case State3:
      {
        digitalWrite(LED1, HIGH);    // turn on LED1
        wait = 3000;                 // wait for 3000ms
        lastMillis = millis();
        mState = State4;
      }
      break;
 
    //***************************    //LEDs OFF
    case State4:
      {
        digitalWrite(LED3, LOW);     // turn off LED3
        wait = 450;                  // wait for 450ms
        lastMillis = millis();
        mState = State5;
      }
      break;
 
    //***************************
    case State5:
      {
        digitalWrite(LED2, LOW);     // turn off LED2
        wait = 450;                  // wait for 450ms
        lastMillis = millis();
        mState = State6;
      }
      break;
 
    //***************************
    case State6:
      {
        digitalWrite(LED1, LOW);     // turn off LED1
        wait = 3000;                 // wait for 3000ms
        lastMillis = millis();
        mState = State7;
      }
 
      break;
 
    //***************************
    case State7:
      {
        blockingFlag = true;
        wait = 3000;                 // wait for 3000ms
        mState = StateStart;
      }
 
      break;
 
    //***************************
    default:
      {
      }
      break;
 
  } //END of switch case
 
} //END of nonBlockingMethod()
 
// ************** END of sketch ****************

nafi04:
How do I change the "several things at once" code to my advantage?

By understanding and applying the principles in it ?

nafi04:
How do I change the "several things at once" code to my advantage?

Do your best. If your modified version does not do what you want then post your code and explain what it actually does and what you would like it to do.

It is much easier to help after you have made a start on the problem.

...R