Anda di halaman 1dari 5

#pragma config(Sensor, dgtl1, btn1,

sensorDigitalIn)
#pragma config(Sensor, dgtl2, btn2,
sensorDigitalIn)
#pragma config(Sensor, dgtl3, btn3,
sensorDigitalIn)
#pragma config(Sensor, dgtl4, lmt1,
sensorDigitalIn)
#pragma config(Sensor, dgtl5, lmt2,
sensorDigitalIn)
#pragma config(Sensor, dgtl6, btn4,
sensorDigitalIn)
#pragma config(Sensor, dgtl7, btn5,
sensorDigitalIn)
#pragma config(Sensor, dgtl10, red,
sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, green,
sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, yellow,
sensorLEDtoVCC)
//*!!Code automatically generated by 'ROBOTC' configuration wizard

!!*//

/*
Project Title: VEX Elevator Project
Team Members: Alyssa Hunt, Levi Villarreal, Samantha Trevino, Zachary Stinson
Date: 11/20/14 - 12/9/14
Section: POE A7
Task Description: An elevator must be able to go to three different floors and turn
on lights when their respective buttons are pressed. A safety function must return
the elevator to the first floor if it is not in use for a long time. For our project
however, we also made our elevator able to go sideways in addition to up and down.
Pseudo code: When button 1 is pressed
Elevator moves to floor one
Light Turns on
Elevator stops
When button 2 is pressed
Elevator moves to floor two
Light Turns on
Elevator stops
When button 3 is pressed
Elevator moves to floor three
Light Turns on
Elevator stops
When no button is pressed for 30 seconds
Elevator moves to floor one
Light Turns on
Elevator stops
When button 4 is pressed
Wheels turn clockwise
Wait 1 second

Stop wheels
When button 5 is pressed
Wheels turn counter-clockwise
Wait 1 second
Stop wheels
*/
task main ()
{
while (1 == 1) { // Loop everything in the while loop because 1 always equals
1
// If floor one button pressed
if(SensorValue[btn1] == 0 && SensorValue [lmt1] == 0 ) { // If
the first floor button is pressed, but it is already at the first flor
turnLEDOn(green); // Turn green LED on for 2 seconds
wait(2);
turnLEDOff(green); // Turn green LED off
} // end if-then statement
if(SensorValue[btn1] == 0 && SensorValue [lmt2] == 0 ) { // If the
first floor button is pressed, and it is at the top floor
turnLEDOn(green); // Turn LED on for 1 second
startMotor(port1, -14); // Turn motot on for 1 second Goes down
if(SensorValue(lmt1) == 0){
stopMotor(port1); // Stop Motor
turnLEDOff(green); // Stop LED
}
} // end if-then statement
if(SensorValue[btn1] == 0 && SensorValue [lmt1] == 1 &&
SensorValue [lmt2] == 1) { // If the first floor button is pressed, and it is not at the
top floor or bottom floor
turnLEDOn(green); // Turn LED on for .5 seconds
startMotor(port1, -14); // Turn motor on for .5 seconds
- Goes down
wait (1);
stopMotor(port1); // Turn motor off
turnLEDOff(green); // Turn LED off
} // end if-then statement

// If 2nd floor button is pressed


if(SensorValue[btn2] == 0 && SensorValue [lmt1] == 1 &&
SensorValue [lmt2] == 1) { // If the second floor button is pressed, and it is not at
the top floor or bottom floor
turnLEDOn(red); // Turn LED on for 2 seconds
wait(2);
turnLEDOff(red); // Turn LED off
} // end if-then statement
if(SensorValue[btn2] == 0 && SensorValue [lmt1] == 0 ) { // If the
second floor button is pressed, and it is at the bottom floor
turnLEDOn(red); // Turn LED on for .5 seconds
startMotor(port1, 25); // Turn motor on for 1 second Goes up
waitInMilliseconds (500);
stopMotor(port1); // Turn motor off
turnLEDOff(red); // Turn LED off
} // end if-then statement
if(SensorValue[btn2] == 0 && SensorValue [lmt2] == 0 ) { // If the
second floor button is pressed, and it is at the top floor
turnLEDOn(red); // Turn LED on for .5 seconds
startMotor(port1, -14); // Turn motor on for .5 seconds
- Goes down
waitInMilliseconds (500);
stopMotor(port1); // Turn motor off
turnLEDOff(red); // Turn LED off
} // end if-then statement

// If 3rd floor button is pressed


if(SensorValue[btn3] == 0 && SensorValue [lmt2] == 0) { // If the
third floor button is pressed, but it is already at the third flor
turnLEDOn(yellow); // Turn LED on for 2 seconds
wait(2);
turnLEDOff(yellow); // Turn LED off
} // end if-then statement

if(SensorValue[btn3] == 0 && SensorValue [lmt1] == 0 ) { // If the


third floor button is pressed, and it is at the bottom floor
turnLEDOn(yellow); // Turn LED on for 1 seconds
startMotor(port1, 25); // Turn motor on for 1 seconds Goes up
wait(1);
stopMotor(port1); // Turn motor off
turnLEDOff(yellow); // Turn LED off
} // end if-then statement
if(SensorValue[btn3] == 0 && SensorValue [lmt1] == 0 &&
SensorValue [lmt2] == 1) { // If the third floor button is pressed, and it is not at the
top floor or bottom floor
turnLEDOn(yellow); // Turn LED on for .5 seconds
startMotor(port1, 25); // Turn motor on for .5 seconds
waitInMilliseconds(500);
stopMotor(port1); // Turn motor off
turnLEDOff(yellow); // Turn Led off
} // end if-then statement

// If Nothing is pressed for 30 seconds


if(SensorValue[btn1] == 1 && SensorValue[btn2] == 1 &&
SensorValue[btn3] == 1 ) { // If none of the buttons are pressed
wait(30); // wait 30 seconds
the bottom floor
seconds

if(SensorValue [lmt1] == 0 ) { // If elevator is at


turnLEDOn(green); // Turn LED on for 2
wait(2);
turnLEDOff(green); // Turn LED off
} // end nested if-then statement
if(SensorValue [lmt2] == 0 ) { // If elevator is at

the top floor


seconds
for 2 seconds - Goes down

turnLEDOn(green); // Turn LED on for 2


startMotor(port1, -20); // Turn motor on

wait(2);
stopMotor(port1); // Turn motor off
turnLEDOff(green); // Turn LED off
} // end nested if-then statement
if(SensorValue [lmt1] == 1 && SensorValue

[lmt2] == 1) {

turnLEDOn(green); // Turn LED on for 1

second

startMotor(port1, -20); // Turn motor on

for 1 second - Goes down

wait(1);
stopMotor(port1); // Turn off motor
turnLEDOff(green); // Turn off LED
} // end nested if-then statement
} // end if-then statement

//If the left button is pressed


if(SensorValue[btn4] == 0) { // If the left button has been pressed
startMotor(port2, 30); // turn both motors on for 2 seconds Goes clockwise
startMotor(port10, -30);
wait(2);
stopMotor(port2); // Stop both motors
stopMotor(port10);
}
//If the right button is pressed
if(SensorValue[btn5] == 0) { // If the right button has been pressed
startMotor(port2, -30); // turn both motors on for 2 seconds Goes counter-clockwise
startMotor(port10, 30);
wait(2);
stopMotor(port2); // Stop both motors
stopMotor(port10);
}
} // end while loop
} // end task main

Anda mungkin juga menyukai