I want to delete the button code on SeveralThingsAtOnce without affecting the servo and LED code. I want to have an LED blink through one cycle throughout the entire loop, so it stops when the servos do since I have motor.detach function. How do I have the LED not block the servos (not delaying the servos) so they go on & off the same time? Here is my code: In this setup, the LED doesn't blink and just turns on & off when the servos do.
#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) {
LED();
digitalWrite(13, HIGH);
}
forward();
delay(500);
right();
delay(500);
forward();
delay(500);
back();
delay(1000);
left();
delay(500);
motorL.detach(); //stops Left SERVO
motorR.detach(); //stops Right SERVO
if (blinkMe == true){ // stops LED
digitalWrite(13, LOW);
}
blinkMe=false;
}