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

//******************************************************************************//
//                              Bug Bot                                         //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your taskbot to move forward indefinately.  While       //
//  moving forward, the robot monitors its touch sensors and if the right touch //
//  sensor is bumbped, the the robot will back up and turn to the left and then //
//  continue moving forward. If the left touch sensor is hit, the robot will    //
//  back up, turn right, and then continue moving forward.                      //
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  The command "random" is used to generate a random number between zero and   //
//  the number contained in parenthises. In this program we see "random(2000);" //
//  which instructs the computer to pick a random number between zero and 2000. //
//                                                                              //
//******************************************************************************//
//				Notes                                           //
//				                                                //
//  none                                                                        //
//                                                                              //
//******************************************************************************//
//				Motors & Sensors                                //
//                                                                              //
//  [I/O Port]     [Name]          [Type]               [Description]           //
//  Port 1         touchsensor1    Touch                Right touch sensor      //
//  port 2         touchsensor2    Touch                Left touch sensor       //
//  Port A         none            Motor                Right Motor             //
//  Port B         none            Motor                Left Motor              //
//                                                                              //
//******************************************************************************//


task main()
{
   int randTime;                           //the variable "randTime" is declared
   wait1Msec(500);                         //the program waits 500 milliseconds before running further code

   while(true)                             //an infinite while loop is delcared with true as its condition
   {
      motor[motorA] = 75;                  //motor A is run at a 75 power level
      motor[motorB] = 75;                  //motor B is run at a 75 power level

      if(SensorValue(touchSensor1) == 1)   //if the value of touchsensor1 is equal to one, this if statement's code will be run
      {
         motor[motorA] = -75;              //motor A is run at a -75 power level
         motor[motorB] = -75;              //motor B is run at a -75 power level
         wait1Msec(750);                   //the program waits 750 milliseconds before running further code

         motor[motorA] = 75;               //motor A is run at a 75 power level
         motor[motorB] = -75;              //motor B is run at a -75 power level
         randTime = random(2000);          //the variable "randTime" is set to equal a rando minteger between 0 and 2000
         wait1Msec(randTime);              //the program waits the number of milliseconds stored in randTime before running further code
      }


      if(SensorValue(touchSensor2) == 1)   //if the value of touchsensor2 is equal to one, this if statement's code will be run
      {
         motor[motorA] = -75;              //motor A is run at a -75 power level
         motor[motorB] = -75;              //motor B is run at a -75 power level
         wait1Msec(750);                   //the program waits 750 milliseconds before running further code

         motor[motorA] = -75;              //motor A is run at a -75 power level
         motor[motorB] = 75;               //motor B is run at a 75 power level
         randTime = random(2000);          //the variable "randTime" is set to equal a rando minteger between 0 and 2000
         wait1Msec(randTime);              //the program waits the number of milliseconds stored in randTime before running further code
      }
   }
}