ROBOTC.net forums
http://robotc.net/forums/

VEX IQ Examples: Line Tracking with Touch LED Indicator
http://robotc.net/forums/viewtopic.php?f=69&t=6770
Page 1 of 1

Author:  tfriez [ Fri Sep 06, 2013 11:56 am ]
Post subject:  VEX IQ Examples: Line Tracking with Touch LED Indicator

To help folks get up and running with the VEX IQ, we're posting a series of VEX IQ videos and sample programs that are included with ROBOTC.

This sample program will perform line tracking using the VEX IQ Clawbot with the VEX IQ Color Sensor. While the robot is line tracking, the VEX IQ Touch LED will be flashing between Red and Green, depending if the robot sees "Dark" or "Light".

You can find this sample program inside of ROBOTC: Look under the "File Menu" and then "Open Sample Programs" inside of the ROBOTC interface.



Code:
#pragma config(Sensor, port5,  lineDetector,   sensorVexIQ_ColorGrayscale)
#pragma config(Sensor, port12, touchLED,       sensorVexIQ_ColorGrayscale)
#pragma config(Motor,  motor1,          leftMotor,     tmotorVexIQ, openLoop, encoder)
#pragma config(Motor,  motor6,          rightMotor,    tmotorVexIQ, openLoop, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   int threshold = 790;      /* found by taking a reading on both DARK and LIGHT    */
                                          /* surfaces, adding them together, then dividing by 2. */

   clearTimer(T1);                  // Resets timer T1 to start counting at 0

   while(time1[T1] < 14000)  // Loops code while timer T1 has counted less than 10 seconds
   {
      if(getColorValue(lineDetector) < threshold)
      {
         setMotorSpeed(leftMotor, 63);      //Set the leftMotor (motor1) to half power (63)
         setMotorSpeed(rightMotor, 0);   //Set the rightMotor (motor6) to off (0)
         setTouchLEDColor(touchLED, colorRed);
      }
      else
      {
         setMotorSpeed(leftMotor, 0);      //Set the leftMotor (motor1) to off (0)
         setMotorSpeed(rightMotor, 63);  //Set the rightMotor (motor6) to half power (63)
         setTouchLEDColor(touchLED, colorGreen);
      }
   }
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/