Let's Make Robots!

Arduino Duemilanove and Ardumoto SparkFun Motor Shield help

Hello all... first post on here :)

 

I am very new to Arduino and coding, for the past few days I have been struggling with some code. I am working towards a small Arduino based rover with two DC motor for movement control. Before I build a body and all that fun stuff I wanted to get basic controls working.

With the code below I can move forward, backward and the BR200# and so on...  (RB case) all work. When I try BF200# nothing happens.. I thought it might be due to the LOW settings on both motors as the HIGH HIGH works ok. 

 

Anyway I am pretty much lost at this point... 

#define PwmPinMotorA 5
#define PwmPinMotorB 6
#define DirectionPinMotorA 3

#define DirectionPinMotorB 2
#define SerialSpeed 9600
#define BufferLength 16
#define LineEnd '#'
 
char inputBuffer[BufferLength];
 
void setup()
{
  // motor pins must be outputs
  pinMode(PwmPinMotorA, OUTPUT);
  pinMode(PwmPinMotorB, OUTPUT);
  pinMode(DirectionPinMotorA, OUTPUT);
  pinMode(DirectionPinMotorB, OUTPUT);
 
  Serial.begin(SerialSpeed);
}
 
// process a command string
void HandleCommand(char* input, int length)
{
  Serial.println(input);
  if (length < 2) { // not a valid command
    return;
  }
  int value = 0;
  // calculate number following command
  if (length > 2) {
    value = atoi(&input[2]);
  }
  int* command = (int*)input;
  // check commands
  // note that the two bytes are swapped, ie 'RA' means command AR
  switch(*command) {
    
    
    case 'FA':
      // motors A & B BACKWARDS
      analogWrite(PwmPinMotorA, value);
      digitalWrite(DirectionPinMotorA, HIGH);
      analogWrite(PwmPinMotorB, value);
      digitalWrite(DirectionPinMotorB, LOW);
      break;
      
    case 'RA':
      // motor A & B FORWARDS
      analogWrite(PwmPinMotorA, value);
      digitalWrite(DirectionPinMotorA, LOW);
      analogWrite(PwmPinMotorB, value);
      digitalWrite(DirectionPinMotorB, HIGH);
      break;
      
    case 'FB':
      // motor A
      analogWrite(PwmPinMotorA, value);
      digitalWrite(DirectionPinMotorA, LOW);
      analogWrite(PwmPinMotorB, value);
      digitalWrite(DirectionPinMotorB, LOW);
      break;
      
    case 'RB':
      // motor B
      analogWrite(PwmPinMotorA, value);
      digitalWrite(DirectionPinMotorA, HIGH);
      analogWrite(PwmPinMotorB, value);
      digitalWrite(DirectionPinMotorB, HIGH);
      
      break;      
          default:
      break;
  }  
}
 
void loop()
{
  // get a command string form the serial port
  int inputLength = 0;
  do {
    while (!Serial.available()); // wait for input
    inputBuffer[inputLength] = Serial.read(); // read it in
  } while (inputBuffer[inputLength] != LineEnd && ++inputLength < BufferLength);
  inputBuffer[inputLength] = 0; //  add null terminator
  HandleCommand(inputBuffer, inputLength);
}