Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

#pragma config(Sensor, in1, lineFollower, sensorLineFollower)

#pragma config(Sensor, in2, potentiometer, sensorPotentiometer)


#pragma config(Sensor, in3, lightSensor, sensorReflection)
#pragma config(Sensor, dgtl1, limitSwitch, sensorTouch)
#pragma config(Sensor, dgtl2, bumpSwitch, sensorTouch)
#pragma config(Sensor, dgtl5, quad,
sensorQuadEncoder)
#pragma config(Sensor, dgtl12, green,
sensorLEDtoVCC)
#pragma config(Motor, port1,
flashlight, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2,
cMotor,
tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3,
taMotor,
tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4,
ttMotor,
tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8,
gMotor,
tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard
!!*//
/*
Project Title:
Team Members:
Date:
Section:
Task Description:
Pseudocode:
*/
//turn table arranged in middle of two cups, cups are arrang'd as specified going clockwise:
//white, wood, clear, aluminum
//*change to match actual hardware
int upperWhiteThreshold = 145;
//values light sensor
or line follower will return
int lowerWhiteThreshold = 142;
//when it senses
indicated marbles.
int upperWoodThreshold = 157;
//all should be
changed according to tests*
int lowerWoodThreshold = 154;
int upperAlThreshold = 153;
int lowerAlThreshold = 151;
int upperClearThreshold = 160;
int lowerClearThreshold = 158;
int turnToWhite = 0;
long ttMotor should run for each bin*
int turnToWood = -63;
int turnToClear = -155;
int turnToAl = -250;

//how

task main()
{
//Program begins, insert code within curly braces
SensorValue(quad) = 0;
int x = 1;
while (x == 1)
//Starts program when switch is pressed
{
if (SensorValue(limitSwitch) == 1)
{
x = 2;
}
}
while(1 == 1)
{

for(int i = 0; i < 3; i++)


{
startMotor(gMotor, 64);
//turn gear just enough to let one marble through*
wait(0.25);
stopMotor(gMotor);
startMotor(gMotor, -64);
wait(0.25);
stopMotor(gMotor);
}
startMotor(cMotor, 40);
//run conv. belt
wait(5);
//wait for 11 sec.
stopMotor(cMotor);
//stop cMotor
turnFlashlightOn(flashlight, 127);
//flashlight fully on
wait(2);
if (SensorValue(lightSensor) <= upperWhiteThreshold &&
SensorValue(lightSensor) >= lowerWhiteThreshold) //if light sensor detects white marble
{
wait(1);
//wait for 1 sec.

startMotor(ttMotor, -20);

//turn turning

table on slow speed


untilEncoderCounts(turnToWhite, 5);
stopMotor(ttMotor);
startMotor(3, 45);
//start taMotor to tilt marble into bin
wait(1);
stopMotor(3);
startMotor(ttMotor, 20);
untilEncoderCounts(0, 5);
stopMotor(ttMotor);
}
else if (SensorValue(lightSensor) <= upperWoodThreshold &&
SensorValue(lightSensor) >= lowerWoodThreshold) //if light sensor detects wood marble
{
wait(1);
//wait for 1 sec.
startMotor(ttMotor, -20);
//turn turning
table on slow speed
untilEncoderCounts(turnToWood, 5);
stopMotor(ttMotor);
startMotor(3, 45);
//start taMotor to tilt marble into bin
wait(1);
stopMotor(3);
startMotor(ttMotor, 20);
untilEncoderCounts(0, 5);
stopMotor(ttMotor);
}
else if (SensorValue(lightSensor) <= upperClearThreshold &&
SensorValue(lightSensor) >= lowerClearThreshold) //if light sensor detects clear marble
{
wait(1);
//wait for 1 sec.
startMotor(ttMotor, -20);
//turn turning
table on slow speed
untilEncoderCounts(turnToClear, 5);
stopMotor(ttMotor);

startMotor(3, 45);
//start taMotor to tilt marble into bin
wait(1);
stopMotor(3);
startMotor(ttMotor, 20);
untilEncoderCounts(0, 5);
stopMotor(ttMotor);
}
else if (SensorValue(lightSensor) <= upperAlThreshold &&
SensorValue(lightSensor) >= lowerAlThreshold)
//if light sensor detects aluminum marble
{
wait(1);
//wait for 1 sec.
startMotor(ttMotor, -20);
//turn turning
table on slow speed
untilEncoderCounts(turnToAl, 5);
stopMotor(ttMotor);
startMotor(3, 45);
//start taMotor to tilt marble into bin
wait(1);
stopMotor(3);
startMotor(ttMotor, 20);
untilEncoderCounts(0, 5);
stopMotor(ttMotor);
}
else;
turnFlashlightOff(flashlight);
}
}

You might also like