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?
How do I set up the boolean?
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();
}
-
Please use [ code ] tags. The forum software will eat some of your code if you don't.
-
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.
-
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.
-
(your real question) Put the declaration outside any function, so it has global scope. Put it at the top, near the servo declarations.
-
If you truly want to run everything just once, put it all in setup(). loop() is allowed to be empty. (but it must exist.)
YAY!