Permalink
Join GitHub today
Light Sensor - This will set the pin as an analog (0 to 1023) pin to be used with light sensors. Line Follower - This will set the pin as an analog (0 to 1023) pin to be used with line follower sensors. Gyro - This sets the pin as a signal pin for a VEX Gyroscope Sensor. Light Sensor: 0 (light) to 4095 (dark). Potentiometer: 0 to 4095. Minimum and maximum values are achieved at opposite ends of travel of the potentiometer and may vary slightly from one potentiometer to another. Line Follower: 0 (light) to 4095 (dark). Values will vary depending on the surfaces being detected and the ambient lighting of the environment.
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up Find file Copy path
Cannot retrieve contributors at this time
#pragma config(Sensor, in1, lineFollowerRIGHT, sensorLineFollower) |
#pragma config(Sensor, in2, lineFollowerCENTER, sensorLineFollower) |
#pragma config(Sensor, in3, lineFollowerLEFT, sensorLineFollower) |
#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed) |
#pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop) |
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// |
/*----------------------------------------------------------------------------------------------------* |
|* - Triple Sensor Line Tracking - *| |
|* ROBOTC on VEX 2.0 CORTEX *| |
|* *| |
|* This program uses 3 VEX Line Follower Sensors to track a black line on a light(er) surface. *| |
|* There is a two second pause at the beginning of the program. *| |
|* *| |
|* ROBOT CONFIGURATION *| |
|* NOTES: *| |
|* 1) Reversing 'rightMotor' (port 2) in the 'Motors and Sensors Setup' is needed with the *| |
|* 'Squarebot' mode, but may not be needed for all robot configurations. *| |
|* 2) Lighting conditions, line darkness, and surface lightness change from place to place, *| |
|* so the value of 'threshold' may need to be changed to better suit your environment. *| |
|* *| |
|* MOTORS & SENSORS: *| |
|* [I/O Port] [Name] [Type] [Description] *| |
|* Motor - Port 2 rightMotor VEX 3-wire module Right side motor *| |
|* Motor - Port 3 leftMotor VEX 3-wire module Left side motor *| |
|* Analog - Port 1 lineFollowerRIGHT VEX Light Sensor Front-right, facing down *| |
|* Analog - Port 2 lineFollowerCENTER VEX Light Sensor Front-center, facing down *| |
|* Analog - Port 3 lineFollowerLEFT VEX Light Sensor Front-left, facing down *| |
*-----------------------------------------------------------------------------------------------4246-*/ |
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++ |
task main() |
{ |
wait1Msec(2000); // The program waits for 2000 milliseconds before continuing. |
int threshold = 505; /* found by taking a reading on both DARK and LIGHT */ |
/* surfaces, adding them together, then dividing by 2. */ |
while(true) |
{ |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ |
displayLCDCenteredString(0, 'LEFT CNTR RGHT'); // Display | |
displayLCDPos(1,0); // Sensor | |
displayNextLCDNumber(SensorValue(lineFollowerLEFT)); // Readings | |
displayLCDPos(1,6); // to LCD. | |
displayNextLCDNumber(SensorValue(lineFollowerCENTER)); // | |
displayLCDPos(1,12); // L C R | |
displayNextLCDNumber(SensorValue(lineFollowerRIGHT)); // x x x | |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ |
// RIGHT sensor sees dark: |
if(SensorValue(lineFollowerRIGHT) > threshold) |
{ |
// counter-steer right: |
motor[leftMotor] = 63; |
motor[rightMotor] = 0; |
} |
// CENTER sensor sees dark: |
if(SensorValue(lineFollowerCENTER) > threshold) |
{ |
// go straight |
motor[leftMotor] = 63; |
motor[rightMotor] = 63; |
} |
// LEFT sensor sees dark: |
if(SensorValue(lineFollowerLEFT) > threshold) |
{ |
// counter-steer left: |
motor[leftMotor] = 0; |
motor[rightMotor] = 63; |
} |
} |
} |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Copy lines Copy permalink