my robot code is missing something and i can't figure it out i am trying to get the motor to turn wile it steers at the same time. i am using millis but for some reason it will set to 90 deg. in setup, but will not execute the loop commands please help :~
#include <Servo.h>
Servo esc; // setup esc just like a servo
Servo sts; // steering servo
boolean steering1flag = true; //steering 1 will only run if this is true
boolean steering2flag = false; //steering 2 will only run if this is true.
unsigned long steeringtimer1;
unsigned long steeringtimer2;
void setup()
{
steeringtimer1 = millis(); //start the watch for steering 1
esc.attach(5); // esc attach to pin 5
sts.attach(9); // steering servo attach to pin 9
esc.writeMicroseconds(1500); // set esc to 0 "or midi-point on servo
sts.write(90); // set steering servo to mid-point
}
void loop()
{
int i;
for (i = 0;i <40; i++) //repeats esc command 40 times
{
esc.writeMicroseconds(1687);// foward
delay(2000);
esc.writeMicroseconds(1330); //reverse
delay(3000);
}
if (millis() - steeringtimer1 >= 3000 && steering1flag == true) //has 4 seconds passed AND do I need to run the steering?
{
sts.write(45); //turn steering servo
steeringtimer2 = millis(); //start the watch for steering 2
steering1flag = false; // steering 1 doesn't need to run again
steering2flag = true; //steering 2 has to go.
}
if (millis() - steeringtimer2 >= 3000 && steering2flag == true)
{
sts.write(135); //turns steering servo
steeringtimer1 = millis(); //start the watch for steering 1
steering2flag = false; //steering 1 has to go again
steering1flag = true; //steering 2 has to wait
}
}