Anda di halaman 1dari 3

#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)

#pragma config(Sensor, in1,


LineFollower, sensorLineFollower)
#pragma config(Sensor, dgtl1, S1,
sensorTouch)
#pragma config(Sensor, dgtl2, S2,
sensorTouch)
#pragma config(Sensor, dgtl3, S3,
sensorTouch)
#pragma config(Sensor, dgtl4, Encoder,
sensorQuadEncoder)
#pragma config(Sensor, dgtl6, F1LED,
sensorLEDtoVCC)
#pragma config(Sensor, dgtl7, F2LED,
sensorLEDtoVCC)
#pragma config(Sensor, dgtl8, F3LED,
sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, count_indicator, sensorLEDtoVCC)
#pragma config(Motor, port2,
Motor,
tmotorVex393_MC29, openLo
op)
//*!!Code automatically generated by 'ROBOTC' configuration wizard
!!*//
/*
Project Title:Elevator
Team Members: Noah Zahm, Riley McBrearty, Justin Alpern, Christian Smith
Date:2/247/2016Section:
Task Description: Build and Program a 3 floor elevator, with buttons to determ
ine where the elevator should go. lights should
turn on, indicating where the elevator is, and as a safety feature, the elevat
or should return to the ground floor after a period
of non-use.
Pseudocode:
Variables referenced:"trip"-used as single variable for motion program. "numbe
r" used for counting button pressed
Subprogram "count" (used to count number of button presses)
turn on red LED, if the first/second/third button is pressed, increase number b
y one
subprogram "motion" (executing command for motion)
if encoder minus trip is greater than 0, move elevator down. if encoder minus tr
ip is less than than 0, move elevator up

*/
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

Anda mungkin juga menyukai