VEX2 Sensors Overview
(→Reflection) |
|||
| Line 40: | Line 40: | ||
|- | |- | ||
| | | | ||
| − | === | + | === Line Follower === |
| − | The | + | The Line Follower sensor, also known as the Reflection sensor, returns values ranging between 0 and 4095. 0 is the lightest reading and 4095 is the darkest. |
<br /> | <br /> | ||
| Line 78: | Line 78: | ||
=== Potentiometer === | === Potentiometer === | ||
| + | Returns an analog value between 0 and 4095 ''(although mechanical stops my limit the values to between 5 and 4092)''. | ||
| + | <br /> | ||
| + | |||
| + | {| | ||
| + | |- | ||
| + | | | ||
| + | <syntaxhighlight lang="ROBOTC"> | ||
| + | #pragma config(Sensor, in1, potentiometer, sensorPotentiometer) | ||
| + | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| + | |||
| + | task main | ||
| + | { | ||
| + | wait1Msec(2000); // wait 2 seconds before exectuing following code | ||
| + | bMotorReflected[port2] = true; // reflects direction of motor on port 2 | ||
| + | |||
| + | while(true) // infinite loop: | ||
| + | { | ||
| + | clearLCDLine(0); // clear the top VEX LCD line | ||
| + | clearLCDLine(1); // clear the bottom VEX LCD line | ||
| + | |||
| + | setLCDPosition(0,0); // set the VEX LCD cursor the first line, first space | ||
| + | displayNextLCDString("Potentiometer:"); // display "Potentiometer:" on the top line | ||
| + | |||
| + | setLCDPosition(1,0); //set the VEX LCD cursor the second line, first space | ||
| + | displayNextLCDNumber(SensorValue(potentiometer)); // display the reading of the potentiometer sensor | ||
| + | |||
| + | wait1Msec(50); // wait 50 milliseconds to help display properly | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
|- | |- | ||
| | | | ||
Revision as of 11:30, 15 February 2012
|
Main >> CORTEX >> Sensors Overview |
| For ROBOTC CORTEX Sensor functions, check out the CORTEX Sensor Functions page! |
|
The VEX 2.0 Cortex is equipped with 20 sensor ports. There are 8 Analog Sensor Ports and 12 Digital Sensor Ports. Note that unlike the VEX - PIC microcontroller, all Analog sensors must be in Analog ports, while all Digital sensors must be in Digital ports. There are a variety of functions and variables used for configuring these ports and accessing their values. Configuring sensors can be complicated. ROBOTC has a built-in wizard that can be used to configure the VEX 2.0 Cortex sensors. The wizard contains a number of PC windows that allow you to set the following fields for the sensor:
|
|
Analog Sensors
| There are 5 main types of Analog Sensors for the VEX CORTEX: | |
Line FollowerThe Line Follower sensor, also known as the Reflection sensor, returns values ranging between 0 and 4095. 0 is the lightest reading and 4095 is the darkest.
| |
PotentiometerReturns an analog value between 0 and 4095 (although mechanical stops my limit the values to between 5 and 4092).
| |
Line Follower | |
Gyro | |
Accelerometer | |
#pragma config(Sensor, S1, touchSensor, sensorTouch) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// task main() { while(SensorValue(touchSensor) == 0) // while the Touch Sensor is inactive (hasn't been pressed): { // DO NOTHING (wait for press) } while(SensorValue(touchSensor) == 1) // while the Touch Sensor is active (pressed): { // DO NOTHING (wait for release) } // YOUR CODE GOES HERE // otherwise (the touch sensor has been activated [pressed] ): motor[motorB] = 75; /* run motors B and C forwards */ motor[motorC] = 75; /* with a power level of 75 */ wait1Msec(1000); // wait 1000 milliseconds (1 second) before moving to further code } |