//*!!Sensor,    S1,          lightSensor, sensorReflection,      ,               !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tSensors lightSensor          = (tSensors) S1;   //sensorReflection   //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.                !!*//

//******************************************************************************//
//                              Timed Line Tracker                              //
//                              RobotC on RCX                                   //
//                                                                              //
//  This program allows your tankbot to follow a line in reverse until a        //
//  specified time is reached, then the program ends.                           //
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  The robot tracks the left side of the line by checking the light reading.   //
//  If the robot reads a light level below the threshold, its on top of a dark  //
//  surface(the line).  So it turns left until it reaches a light surface.      //
//  Once the robot reads a light surface, it will turn right until it reads a   //
//  dark surface again.  By bouncing between left and right turns, we achieve   //
//  linear motion along the black line.                                         //
//                                                                              //
//******************************************************************************//
//				Notes                                           //
//				                                                //
//  1. The light sensor is attached to the back of the robot                    //
//  2. Be sure to take readings of your light sensor over the light and dark    //
//     areas. Once you have the values, add them and divide by 2 to find your   //
//     threshold. Then, use your threshold as a comparison in your program.     //
//  3. To adjust how long the robot runs, change the "10000" to the number of   //
//     milliseconds you wish to run it it for.                                  //
//                                                                              //
//******************************************************************************//
//				Motors & Sensors                                //
//                                                                              //
//  [I/O Port]          [Name]          [Type]          [Description]           //
//  Port A              none            Motor           Right Motor             //
//  Port B              none            Motor           Left Motor              //
//  Port 1              lightsensor     Light Sensor    none                    //
//                                                                              //
//******************************************************************************//


task main()
{
  time1(T1) = 0;	               //timer "T1" is reset to 0

  while(time1(T1) < 10000)             //a while loop is delcared with the timer "T1" being less than 10 seconds as its true condition
  {
    if(SensorValue(lightSensor) < 45)  //if the lightsensor reads a value less than 45 the if code will be run
    {
      motor[motorA] = 100;             //motor A is run at a 100 power level
      motor[motorB] = -60;             //motor B is run at a -60 power level
      wait1Msec(300);                  //the program waits 300 milliseconds before running further code
    }
    else                               //if the lightsensor reads a value greater than or equal to 45 the the else's code will be run
    {
      motor[motorA] = -60;             //motor A is run at a -60 power level
      motor[motorB] = 100;             //motor A is run at a 100 power level
    }
  }
}