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

//******************************************************************************//
//                              Clap Off                                        //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your robot to move forward until a loud nouse is made.  //
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  The focus of this program is to demonstrate using the sound sensor in a program.
//  The program is a basic while loop, where a robot will move forward as long as it doesn't hear
//  a loud sound.                                                                 //
//                                                                              //
//******************************************************************************//
//				Notes                                           //
//				                                                //
//  1. The one second delay is needed to avoid obtainng inaccurate intial       //
//     readings.                                                                //
//                                                                              //
//******************************************************************************//
//				Motors & Sensors                                //
//                                                                              //
//  [I/O Port]     [Name]          [Type]               [Description]           //
//  Port 1         soundsensor     Sound Db             port 1 sound sensor     //
//  Port A         none            Motor                Right Motor             //
//  Port B         none            Motor                Left Motor              //
//                                                                              //
//******************************************************************************//


task main()
{
   wait1Msec(1000);                        //the program waits 1000 milliseconds before running further code

   while(SensorValue(soundsensor) <= 50)   //a while loop is delcared with the sound sensor value being less than or equal to as its true 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
   }
}