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

//******************************************************************************//
//                              Line Tracker                                    //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your taskbot to follow a line in reverse.               //
//                                                                              //
//******************************************************************************//
//				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.     //
//                                                                              //
//******************************************************************************//
//				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()
{
   while(true)                           //an infinite while loop is declared with"true" as its 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
      }
   }
}