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

//******************************************************************************//
//                              line Tracking for Rotations                     //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your robot to track a line using its light sensor. It 	//
//  will do so until a set number of rotations has been reached by the motor    //
//  encoder.  Taskbot is used for this program.                                 //
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  The robot is able to follow the line by continuely turning towards it. By   //
//  keeping one tire stationary and allowing the other to move forward, the	//
//  robot slides one side at a time forward.                                    //
//                                                                              //
//******************************************************************************//
//				Notes                                           //
//				                                                //
//  1. The light Sensor is mounted on the back of the robot.                    //
//  2. Be sure to reset the rotation sensor before comparing its value.         //
//                                                                              //
//******************************************************************************//
//				Motors & Sensors                                //
//                                                                              //
//  [I/O Port]     [Name]          [Type]               [Description]           //
//  Port 1         lightsensor     Active Light Sensor  Front/downward mounted     //
//  Port A         none            Motor                Right Motor             //
//  Port B         none            Motor                Left Motor              //
//                                                                              //
//******************************************************************************//


task main()
{
   nMotorEncoder[motorA] = 0;             //the rotation sensor for motor A is reset to 0

   while(nMotorEncoder[motorA] < 1800)   //a while loop is delcared with the rotation sensor for motor A less than 1800 as its true condition
   {
      if(SensorValue(lightSensor) < 45)   //an if statement is declared with the light sensor's value being less than 45 as its true condition
      {
         motor[motorA] = 75;             //motor A is run at a 75 power level
         motor[motorB] = 0;               //motor B is run at a 0 power level
      }

      else                                //an else statement is declared holding the opposite of the if's statement as its true condition
      {
         motor[motorA] = 0;               //motor A is run at a 0 power level
         motor[motorB] = 75;             //motor A is run at a 75 power level
      }
   }
}