my partner and I are finishing our marble sorter for a final grade in our PoE class we have the hardware portion pout together and some of the code has been put together, but the line follower and finishing motor wont work here’s the code and a picture of the hardware
#pragma config(Sensor, in1, cupReader, sensorPotentiometer)
#pragma config(Sensor, in2, marbleSorter, sensorLineFollower)
#pragma config(Sensor, dgtl1, startButton, sensorTouch)
#pragma config(Motor, port2, sorterGear, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port3, cupGears, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port4, startServo, tmotorServoStandard, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
/*
Project Title: Marble Sorter
Team Members:Colton M. Gabe W.
Date:3/28/19
Task Description: Create a machine that can determine the difference in 4 different marbles when inserted into the machine.
*/
//Funtion Declarations
void moveMarbles();
void sortMarbles();
task main()
{
moveMarbles();
sortMarbles();
}
void moveMarbles()
{
while(1==1)
{
motor[startServo]=-127;
wait1Msec(1000);
motor[startServo]=127;
wait1Msec(5000);
}
}
void sortMarbles()
{
while(1==1)
{
if(SensorValue(marbleSorter)>2044) //if the marble is opaque
{
if(SensorValue(cupReader)==4095) //if the wood cup is under the reader
{
while(SensorValue(cupReader)!= 0) //while the cup under the reader is not the opaque cup
{
motor[cupGears]=20; //move motor
}
motor[sorterGear]=20; //let the marble go
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
wait1Msec(500); //wait half sec
motor[sorterGear]=-20; //reset marble stopping gear
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
}
else if(SensorValue(cupReader)==2070) //if the aluminium cup is under the reader
{
while(SensorValue(cupReader)!= 0) //while the cup under the reader is not the opaque cup
{
motor[cupGears]=-20; //move motor
}
motor[sorterGear]=20; //let the marble go
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
wait1Msec(500); //wait half sec
motor[sorterGear]=-20; //reset marble stopping gear
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
}
else //if the cup under reader is opaque cup
{
motor[sorterGear]=20; //let the marble go
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
wait1Msec(500); //wait half sec
motor[sorterGear]=-20; //reset marble stopping gear
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
}
}
else if(SensorValue(marbleSorter)<2100 && SensorValue(marbleSorter)>1388) //determines if the marble is aluminium
{
if(SensorValue(cupReader)==0) //if the cup under reader is opaque
{
while(SensorValue(cupReader)!= 2070) //while the cup under reader is not wood
{
motor[cupGears]=20; //move motor
}
motor[sorterGear]=20; //let the marble go
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
wait1Msec(500); //wait half sec
motor[sorterGear]=-20; //reset marble stopping gear
wait1Msec(500); //wait half sec
motor[sorterGear]=0; //stop motor
}
else if(SensorValue(cupReader)==4095) //if the cup under the reader is
{
while(SensorValue(cupReader)!= 2070)
{
motor[cupGears]=20;
}
motor[sorterGear]=20;
wait1Msec(500);
motor[sorterGear]=0;
wait1Msec(500);
motor[sorterGear]=-20;
wait1Msec(500);
motor[sorterGear]=0;
}
else
{
motor[sorterGear]=20;
wait1Msec(500);
motor[sorterGear]=0;
wait1Msec(500);
motor[sorterGear]=-20;
wait1Msec(500);
motor[sorterGear]=0;
}
}
else //if marble is wood
{
if(SensorValue(cupReader)==0)
{
while(SensorValue(cupReader)!= 4095)
{
motor[cupGears]=20;
}
motor[sorterGear]=20;
wait1Msec(500);
motor[sorterGear]=0;
wait1Msec(500);
motor[sorterGear]=-20;
wait1Msec(500);
motor[sorterGear]=0;
}
else if(SensorValue(cupReader)==2070)
{
while(SensorValue(cupReader)!= 4095)
{
motor[cupGears]=20;
}
motor[sorterGear]=20;
wait1Msec(500);
motor[sorterGear]=0;
wait1Msec(500);
motor[sorterGear]=-20;
wait1Msec(500);
motor[sorterGear]=0;
}
else
{
motor[sorterGear]=20;
wait1Msec(500);
motor[sorterGear]=0;
wait1Msec(500);
motor[sorterGear]=-20;
wait1Msec(500);
motor[sorterGear]=0;
}
}
}
}