*/
int number; int trip; int floor1=0; int floor2=520; int floor3=1142;
void motion()
{
if(SensorValue(dgtl4)-trip>0)
//if the elevator is higher than desired floor, go down
{startMotor(port2, -25);
waitUntil(SensorValue(dgtl4)-trip<100 && SensorValue(dgtl4)-trip>-100);
stopMotor(port2);
}
else
//if it isn't (i.e. its lower), go up
{startMotor(port2, 25);
waitUntil(SensorValue(dgtl4)-trip<100 && SensorValue(dgtl4)-trip>-100);
stopMotor(port2);
}
}
void count()
{number=0; turnLEDOff(dgtl12);
clearTimer(T2);
while(time1[T2]<7000)
{
turnLEDOn(dgtl12);
//turns on LED so the user know the computer is reading counting
if (SensorValue(dgtl1)==1)
//increases value of "number" with each button press
{number=number+1;}
if (SensorValue(dgtl2)==1)
{number=number+1;}
if (SensorValue(dgtl3)==1)
{number=number+1;}
waitInMilliseconds(175);
if (number>3)
//if too many buttons are pressed, sets number to 3 to prevent glitching
{number=3;}
}
turnLEDOff(dgtl12);
}
task floors()
//correct LED is lit with each floor
{SensorValue(dgtl4)=0;
repeat(forever)
{
if (floor1-SensorValue(dgtl4)>-100&&floor1-SensorValue(dgtl4)<100)
//if the elevator is 100 encoder values within desired floor
{turnLEDOn(dgtl6);}
//turn on the appropriate LED
else
{turnLEDOff(dgtl6);}
//if it isn't in then turn the light off
if (floor2-SensorValue(dgtl4)>-100&&floor2-SensorValue(dgtl4)<100)
{turnLEDOn(dgtl7);}
else
{turnLEDOff(dgtl7);}
if (floor3-SensorValue(dgtl4)>-100&&floor3-SensorValue(dgtl4)<100)
{turnLEDOn(dgtl8);}
else
{turnLEDOff(dgtl8);}
}
}
task main()
{startTask(floors);
repeat(forever)
{
while(trip==0)
//while there is no assigned trip, collect readings from the buttons
{if(SensorValue(dgtl1)==1)
{trip=floor1;}
if(SensorValue(dgtl2)==1)
{trip=floor2;}
if(SensorValue(dgtl3)==1)
{trip=floor3;}
}//while trip close
motion();
//execute the movement
count();
//recieve input for the # of button presses
if(number==1)
//takes info from "number" (the number of times the button has been presse)
{trip=floor1;}
if(number==2)
{trip=floor2;}
if(number==3)
{trip=floor3;}
motion();
if(number==0)
{trip=floor1;
motion();}
}//repeat close
}//main close