How do I make an LED blink while not affecting servos.

I’m trying to find a way to make the LED blink through 1 cycle once through the entire loop while not affecting the servo time. I want to stop the LED because of the motor.detach function that stops the servo from going through the loop again and I want the LED to stop with the servos.

Here is the loop without any boolean variables or LED function.

  void loop() {
  forward();
  delay(500);
  right();
  delay(500);
  forward();
  delay(500);
  back();
  delay(1000);
  left();
  delay(500);
  motorL.detach();
  motorR.detach();   <- DETACHES THE SERVOS

}

Here is the loop where the LED stops with the servos and is on when the servos are on, but doesn’t blink.

void loop () {
  if (blinkMe == true) {   
    LED();
    digitalWrite(13, HIGH);
  }
  forward();
  delay(500);
  right();
  delay(500);
  forward();
  delay(500);
  back();
  delay(1000);
  left();
  delay(500);
  motorL.detach();
  motorR.detach();
 if (blinkMe == true){
  digitalWrite(13, LOW);
    }
    blinkMe=false;
}

Read this post

How do I change the code so that only 1 LED from pin 13 blinks through 1 cycle in the entire loop?

By getting rid of all those delay() statements, and using the technique linked by J-M-L.

The delays in my code or the ones in ServerlThingsAtOnce?

Are there any in STATST?

What are statst?

nafi04:
What are statst?

Several things at the same time; don't worry, I also had to think about that for a little while :wink:

Please learn to post code using code tags
type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

The result look like

your code here

Right, sorry, I thought the abbrev was obvio. ... :wink: (actually I was posting from my phone, and the fewer characters I need to type, the better!)

Nafi, the Several Things thread will show you how to control timing without using delay(). While delay() has it place, and can be used effectively, using it to control actions in real time is not one of those uses. This is because when delay() executes, everything else stops. So the sketch cannot turn off an LED, move a servo, ... nada! This effect is called "blocking". The goal of most Arduino programming is to write non-blocking code, so it can be used to do ... several things at the same time!

So do take a look at Robin2's program - it does all that stuff. You will likely be able to modify the code and make it do what you want your sketch to do. Once you have it running, come back here and we'll help you iron out the details.

void loop ()

{
  if (blinkMe == true)
  {
    LED();
    digitalWrite(13, HIGH);
  }
    ...
    ...
  if (blinkMe == true)
  {
    digitalWrite(13, LOW);
  }
  blinkMe = false;
}

Of course it does not blink (or better, only once). For the simple reason that you set 'blinkMe' to false at the end of the loop.

Once you take that out, it will blink at a high rate where you will not be able to see that it's off; 3 seconds on, less than a millisecond off.

How do I delete the button code without affecting the other code?

No idea what you're talking about. Is blinkMe part of the button code? Or are you talking about something else?

BlinkMe is a boolean. Full code:

#include <Servo.h>
Servo motorL;
Servo motorR;
boolean blinkMe = true;
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 () {
  if (blinkMe == true) {    //has to be == or will not work
    LED();
    digitalWrite(13, HIGH);
  }
  forward();
  delay(500);
  right();
  delay(500);
  forward();
  delay(500);
  back();
  delay(1000);
  left();
  delay(500);
  motorL.detach();
  motorR.detach();
 if (blinkMe == true){
  digitalWrite(13, LOW);
    }
    blinkMe=false;
}

Yep, but where is that button code that you want to remove?

The button codes on SeveralThingsAtOnce.
So how do I delete the button code on SeveralThingsAtOnce since I don't have a button.

Have you studied the several things at the same time code?