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

//******************************************************************************//
//                              Sonar Display                                   //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your robot to move forward indefinately and displa its  //
//  sonar value on the screen in centimeters.
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  The text parameter is what shows up on the screen in the  display command's //
//  parenthises. This will be the test enclosed in quotes that is up to 16      //
//  characters long. You may also display variables within this parameter by    //
//  using the "%d" command to display a variable definined in the parameter     //
//  after the quotes. You may use up to 3 "%d" characters to display 3 seperate //
//  variables. Remeber that you can only display 16 total characters, so the    //
//  value of the variables will take up some of those 16 characters.            //
//                                                                              //
//******************************************************************************//
//				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         sonarsensor      Sonar Sensor         port 1 sonarsensor     //
//  Port A         none             Motor                Right Motor            //
//  Port B         none             Motor                Left Motor             //
//                                                                              //
//******************************************************************************//


task main()
{
   int x=0;                                         //the variable "x" is declared as an integer, and initialized to equal zero

   while(true)                                      //an infinite while loop is delcared with true as its condition
   {
      x = SensorValue(sonarSensor);                 //the variable "x" is set to take the value of the sonar sensor
      nxtDisplayTextLine(1,"Sonar Reading:%d",x);   //"Sonar Reading:" followed by the value of the variable "x" will be displayed on line 1 of the screen of the NXT
      wait1Msec(1000);                              //the program waits 1000 milliseconds before running further code
      eraseDisplay();                               //the NXT display is cleared
   }
}