Code: one way it can be done

Printer-friendly version

Please copy and paste the code in to robotc so you can read it easyer i am seeing what i can do with the color code.

{syntaxhighlighter brush: cpp}
#pragma config(Sensor, S1, right, sensorI2CHiTechnicCompass)
#pragma config(Sensor, S2, middle, sensorI2CHiTechnicCompass)
#pragma config(Sensor, S3, left, sensorI2CHiTechnicCompass)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main
{
while(true)
{
int rat = SensorValue(S1);
int cat = SensorValue(S2);
int dog = SensorValue(S3);
int Compass = ((rat+cat+dog)/3);
/*
This is meant to take the mean of the 3 sensors to give you a more accrete answer
*/

if (Compass < 178)
{
motor[motorA]=50;
motor[motorC]=-50;
}
/*
if the mean of the 3 sensors is less then 178 then turn left
*/

if (Compass >182)
{
motor[motorA]=-50;
motor[motorC]=50;
}
/*
if the mean of the 3 sensors is greater then 182 then turn right
*/

if (Compass <182 && Compass> 179)
{

motor[motorA]=0;
motor[motorC]=0;
PlaySound(soundBeepBeep);
wait1Msec(1000);
/*
this makes the robot stop and beep for 1.5 sec so that you have time to
mark which way the sensor is pointing
*/
int pug= (rand()/5);// rand() just genrates a random number
nSyncedMotors =(synchAC);
nSyncedTurnRatio=-100;
motor[motorA]=pug;
wait1Msec(pug);
nSyncedMotors=(synchNone);
}
/*
this is just to make sure that it is nice and mixed up so i
have a accurate anser
*/

}
}

{/syntaxhighlighter}

Attached Files: