Old versionProgram is attached as Text File at: https://falcon.tamucc.edu/~wiki/uploads/Katz/DFRobotMotoSeedSensor1.txt

//-----------
// Adafruit Motor shield library
// based on copyright Adafruit Industries LLC, 2009
//  copyright Louis Katz 2012
//This code is an intermediate save of a program using an Ardumino Uno (rev 3) a Lady Ada Motor Shield (v 1.0). A Seeed Studio Grove Board, two //Grove IR Sensors, and a Dagu DG008 4 wheel robot.
//The code calls functions to run the motors(4) and read the sensors(2)
//use at your own risk
// this code is public domain, enjoy!
#include <AFMotor.h>
AF_DCMotor motorLF(4);//LeftFront
AF_DCMotor motorRF(3);//RightFront
AF_DCMotor motorLR(1);//LeftRear
AF_DCMotor motorRR(2);//RightRear
//------------------------------
//Configuration Variables 
int maxspeed = 255;// Sets maximum voltage to the DC motors. At 255 this is supposedly 1.5 V lower than the motor shield supply voltage.
int accel=1; //acceleration 1-255". 1 is most gradual. 255 is on/off. Note: "1" saves wear and tear on the motor and gearbox. 
int decel=1;//deceleration 1-255. "1"is most gradual 255 is on off. Note: "1" will prevent quick stops.
int continuous = 0; //"0" turns off motor (.release) before each sensor read. "1" leaves it going unless told to stop.
//Grove IR Distance Sensor Sharp 2Y0A2
int Delay=500;//lenght of wait time in milliseconds (note case)
const int analogInPin0 = A1;  // Analog input pin that Right Distance Sensor A0,A1
const int analogInPin1 = A3; // Left Distance Sensor A2,A3
 // Analog input pin that  is attached to
int sensVal[6] = {0, 0, 0, 0, 0,0};//Array for storing Sensor Values and  passing from subroutine
int y;int x; //variables for passing into and out of functions
int softTurnRatio = 60;
//--------------------------------
int Runtime=500;//The length of time the motors run if continuous variable is set to off "0".  ??can be set up in the runMotor function call.
  int LFRunSpeed;int LFDirection;int RFRunSpeed;int RFDirection;
  int LRRunSpeed;int LRDirection;int RRRunSpeed;int RRDirection;
//--------------------------------
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");//click the magnifying glass icon in upper right to see the serial monitor
   // Turnoff motors
  motorLF.run(RELEASE);motorRF.run(RELEASE);motorLR.run(RELEASE);motorRR.run(RELEASE);
}
//-------------------------------------
void loop() {
  uint8_t i;
  //int x;
  delay(250); 
  x = readSens (1);
//end sensor read section
  x = runMotors (Runtime,maxspeed,0,maxspeed,0,maxspeed,0,maxspeed,0);//all backward
  delay (Delay);
  x = runMotors (Runtime,maxspeed,1,maxspeed,1,maxspeed,1,maxspeed,1);// all forward
  delay (Delay);
  x = runMotors (Runtime,maxspeed,0,maxspeed,1,maxspeed,0,maxspeed,1);//swivel left
  delay (Delay);
  x = runMotors (Runtime,maxspeed,1,maxspeed,0,maxspeed,1,maxspeed,0);//swivel right
  delay (Delay);
  x = runMotors (Runtime,(maxspeed*softTurnRatio/100),1,maxspeed,1,(maxspeed*softTurnRatio/100),1,maxspeed,1);//soft turn
  delay (Delay);
  x = runMotors (Runtime,maxspeed,1,(maxspeed*softTurnRatio/100),1,maxspeed,1,(maxspeed*softTurnRatio/100),1);//soft turn

}
//runMotors Function code
int runMotors (int Runtime, int LFRunSpeed, int LFDirection, int RFRunSpeed, int RFDirection, int LRRunSpeed, int LRDirection, int RRRunSpeed, int RRDirection)
{
  //Serial.print(LFDirection);
  if (LFDirection == 1.0) {motorLF.run(FORWARD);}
  else {motorLF.run(BACKWARD);}

  if (RFDirection == 1) {motorRF.run(FORWARD);}
   else{motorRF.run(BACKWARD);}

  if (LRDirection == 1) {motorLR.run(FORWARD);}
   else{motorLR.run(BACKWARD);}

  if (RRDirection == 1) {motorRR.run(FORWARD);}
   else{motorRR.run(BACKWARD);}

   motorLF.setSpeed(LFRunSpeed);motorRF.setSpeed(RFRunSpeed);motorLR.setSpeed(LRRunSpeed);motorRR.setSpeed(RRRunSpeed);
   //if Runtime = 9999 then do not delay and just return. If runtime is other then delay Runtime in milliseconds
   if (Runtime != 9999)
   {delay (Runtime);}
    motorLF.run(RELEASE);motorRF.run(RELEASE); motorLR.run(RELEASE);motorRR.run(RELEASE);
    return Runtime;

}
//checkSensors function code
int readSens (int x)
{ int i;//counter
  int  sum0 =0;//Right Sensor Sum for Averaging  
  int  sum1 =0;//Left
 // Serial.print(analogRead(analogInPin0));Serial.print("  ---  ");Serial.println(analogRead(analogInPin1));
  // read the analog in value:
  for (int i =0;i<20;i++)
  {sum0 = sum0+analogRead(analogInPin0);
   sum1 = sum1+analogRead(analogInPin1); }
  sensVal[0]= sum0 / 20 ; 
  sensVal[1]= sum1 / 20 ; 
  Serial.print(sensVal[0]);Serial.print("  ---  ");Serial.println(sensVal[1]);//PrintSensor Values

  delay(500); 
  return (y);
}

//----------