Im new to arduino programming, in fact this is my first project. I'm using the arduino to control a Traxxas Stampede with and ESC. I want the program to make the car turn left, go forward, stop, turn right, go backward, stop, and repeat. The problem is that it will turn left, go forward, stop, turn right, then do nothing, and repeat. What's weird to me is that once in a while it will go backwards when it should, but only about once every minute or so. If i modify both of the functions to go forward only, it works fine, same as if modify it to only go backwards. Here is the code I put together.
//Test Routine Program - By Stezipoo
#include <Servo.h>
//create servo objects
Servo steering;
Servo throttle;
int ledPin = 13;
int center = 95;
int right = 55;
int left = 130;
void setup()
{
pinMode(9, OUTPUT); //sets pin 9 to output
pinMode(10, OUTPUT);
steering.attach(9); // attach steering servo to pin 9
throttle.attach(10); // attach ESC to pin 10
steering.write(95); // centers steering
throttle.write(90); // sets mid throttle
}
void loop()
{
goLeft();
goRight();
}
void goLeft() // turn left, then go foward and stop
{
steering.write(left); // turn left
delay(10);
digitalWrite(ledPin, HIGH);
delay(500);
throttle.write(120); // go forward
delay(500);
throttle.write(90);
digitalWrite(ledPin, LOW);
delay(2000);
}
void goRight() // turn right, then go backward and stop
{
steering.write(right); // turn right
delay(10);
digitalWrite(ledPin, HIGH);
delay(500);
throttle.write(60); // go backward
delay(500);
throttle.write(90);
digitalWrite(ledPin, LOW);
delay(2000);
}
Any suggestions on how to solve this problem would be greatly appreciated =]