This code below allows the NXT to run forward until it detects a light surface:
const tSensors lightSensor          = (tSensors) S1;   //sensorLightActive  
task main()
{
   wait1Msec(50);                        //the program waits 50 millisecond to initialize the light sensor
   while(SensorValue(lightSensor) //a loop that will keep looping while the light sensor's value is less than 45.
   {
      motor[motorA] = 100;                //motor A is run at a 100 power level
      motor[motorB] = 100;                //motor B is run at a 100 power level
   }
   motor[motorA] = 0;                      //motor A is stopped with a 0 power level
   motor[motorB] = 0;                      //motor B is stopped with a 0 power level
}
This code below allows the NXT to move forward until it detects an obstacle and then stops.                                                             
const tSensors sonarSensor          = (tSensors) S1;   //sensorSONAR        
task main()
{
   while(SensorValue[sonarSensor] > 20) 
   {
      motor[motorA] = 75;                  //motor A is run at a 75 power level
      motor[motorB] = 75;                  //motor B is run at a 75 power level
   }
}
At this stage I am very familiar with most of the function that are needed and I understand all abilities of RobotC that is needed for my research. 
Time: 4 hrs.
No comments:
Post a Comment