Stealth0113:
Just upload a sketch that only turn on/off the motor's. It seems like you have not enough power to let te motors spin. How do you feed the motor(shield)? I hope not via the 5v of the arduino because that pin doesn't have enough current.
I am supplying common power for arduino and motor shield through the motor shield.
My motors variables are:
AF_DCMotor motorBack(4, MOTOR12_64KHZ);
AF_DCMotor motorFront(1, MOTOR12_64KHZ);
The car goes only forward or stops, so for the motorBack my turn on/off motor's function is:
void SetMotorSpeed(int val) {
if (mySpeed == val)
return;
mySpeed = val;
motorBack.setSpeed(mySpeed);
motorBack.run(FORWARD);
}
passing parameter 0 to the function above makes the motor stop.
For the motorFront, which is used for making turns, there are three functions, turn left, right and straight:
void turnRight() {
if (turnState != 1) {
setMotorSpeed(0); // for motorBack
motorFront.run(FORWARD);
turnState = 1;
delay(100);
setMotorSpeed(motorTurnSpeed); // motorTurnSpeed = 255
}
}
void turnLeft() {
if (turnState != 0) {
setMotorSpeed(0); // for motorBack
motorFront.run(BACKWARD);
turnState = 0;
delay(100);
setMotorSpeed(motorTurnSpeed); // motorTurnSpeed = 255
}
}
void turnStraight(int cycle) {
if (turnState != 2) {
setMotorSpeed(0); // For back motor
if (turnState == 0) {
motorFront.run(FORWARD);
delay(cycle); // wait until wheels turn straight
motorFront.run(RELEASE);
} else if (turnState == 1) {
motorFront.run(BACKWARD);
delay(cycle); // wait until wheels turn straight
motorFront.run(RELEASE);
}
turnState = 2;
setMotorSpeed(motorStraightSpeed); // motorStraightSpeed = 200
}
}