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

//******************************************************************************//
//                              Timed Line Tracker                              //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your taskbot 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 Active    Front/downward mounted
//
//                                                                              //
//******************************************************************************//


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] = 75;             //motor A is run at a 75 power level
      	motor[motorB] = 0;               //motor B is stopped with a 0 power level
      }

      else                                //if the lightsensor reads a value greater than or equal to 45 the the else's code will be run
      {
      	motor[motorA] = 0;               //motor A is stopped with a 0 power level
      	motor[motorB] = 75;             //motor B is run at a -75 power level
      }
   }
}