How do I stop an LED for good after it went throgh 1 cycle (loop)?

I am doing servos and LEDS at the same time and I want to disable the LED for good once the servos are detached. Is there a function I need to be using?

Make yourself a Boolean variable. Set it to true at the beginning. Put the led stuff you want to stop inside an if statement that checks that variable. When you want to stop doing that part, set your variable to false.

How do I set up the boolean?

Just like any other variable.

boolean giveMeAName = false;

Where do I put it?

#include <Servo.h>
const int x=500;
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 (){
LED();
digitalWrite(13,HIGH);
forward();
delay(500);
stop();
delay(x);
right();
delay(500);
stop();
delay(x);
forward();
delay(500);
stop();
delay(x);
back();
delay(1000);
stop();
delay(x);
left();
delay(500);
stop();
delay(x);
motorL.detach();
motorR.detach();
}

  1. Please use [ code ] tags. The forum software will eat some of your code if you don't.

  2. There is a standard layout for the position of the braces ({}). Use the auto-format tool on the Arduino Tools menu to do this for you. It might initially seem like it's scrambling your code but it's actually much easier to read the code that way.

  3. Your LED() function just says that you're going to use pin 13 as an output. It never actually outputs anything. By default, it will be LOW, or off.

  4. (your real question) Put the declaration outside any function, so it has global scope. Put it at the top, near the servo declarations.

  5. If you truly want to run everything just once, put it all in setup(). loop() is allowed to be empty. (but it must exist.)

Holy Moly, one statement per line man. This makes code hard for others to read, which makes it hard to get help:

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

Where to put it is up to you. You know where in your code you want things to happen. Here's an example. See if you can follow what happens. If this doesn't just scream stupid simple then you need to spend some time with some simpler examples than the code you have and learn how to put code together.

boolean blinkMe = true;

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

void loop(){
    if (blinkMe == true){
           digitalWrite(13, HIGH);
           delay(500);
           digitalWrite(13, LOW);
           delay(500);
    }
    blinkMe = false;
}

It's not a magic drop in a few lines of code thing. Understand how and why that code only blinks the led once and you'll be able to use this anywhere you want.

YAY!