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); } } } |