Elevator Project

task main()
{
while ( 1 == 1)
{
{
if(SensorValue(dgtl2==1))
{
startMotor (Elevator , 25);
wait(6.1);
stopMotor (Elevator);
}
}
{
if(SensorValue(dgtl1==1))
{
startMotor (Elevator , 25);
wait(12.2);
stopMotor(Elevator);
}
}
{
if(SensorValue(dgtl4==1))
{
startMotor (Elevator , -25);
wait(6.4);
stopMotor (Elevator);
}
}
{
if(SensorValue(dgtl3==1))
{
startMotor (Elevator , 25);
wait (6.1);
stopMotor (Elevator);
}
}
{
if(SensorValue(dgtl6==1))
{
startMotor (Elevator , -25);
wait(14.2);
stopMotor(Elevator);
}
}
{
if(SensorValue(dgtl5==1))
{
startMotor (Elevator , -25);
wait (6.1);
stopMotor (Elevator);
}
}
}
}

I am doing the Elevator project for POE. Whenever I start the program the motor starts automatically, I am just confused as to how to make each button work independently.

Try using an else statement and see if it fixes the problem. That will create a base state of resting. It could also be as simple as you need to cycle your cortex power completely off and on or robotc itself.

Add in an
else
{
motor (Elevator) =0;
}

You shouldn’t have the extra { between the if and the while. Brackets should only begin and end each of your conditional statements (if&while in this case), not go around them…

#fixformattingisyourfriend

For
‘if(SensorValue(dgtl2==1))’,
I think it should say: if(SensorValue[dgtl2]==1)

Is that even ROBOTC?
There is so many errors that I don’t really think it would be…

I think it’s the Natural Language version.

I could try to make a sample program for you :slight_smile:
And yes, Natural Language is ROBOTC…
Just tell me all the ports and I would write one for you, and what button you want to press to activate that motor…

@DeadMagicSocial Here’s my finished product, you should’ve added ‘else if’ and ‘else’. Also including to stop the motors when nothing is pressed… It should work (Plus you had too many ‘}’ in the code);


task main() //Start task
{
while ( 1 == 1) //While Remote is connected
{
if(SensorValue[dgtl2]==1) //While Dgtl2 is active
{
motor[Elevator]=25; //Motor Elevator at 25 power
wait1000msec(6.1); //Wait 6.1 seconds
motor[Elevator]=0; //Motor elevator at 0 power
}
else if(SensorValue[dgtl1]==1) //While Dgtl1 is active
{
motor[Elevator]=25; //Motor Elevator at 25 power
wait1000msec(12.2); //Wait 12.2 seconds
motor[Elevator]=0; //Motor Elevator at 0 power
}
else if(SensorValue[dgtl4]==1) //While Dgtl4 is active
{
motor[Elevator]=-25; //Motor Elevator at -25 power
wait1000msec(6.4); //Wait 6.4 seconds
motor[Elevator]=0; //Motor Elevator at 0 power
}
else if(SensorValue[dgtl3]==1) //While Dgtl3 is active
{
motor[Elevator]=25; //Motor Elevator at 25 power
wait1000msec(6.1); //Wait 6.1 Seconds
motor[Elevator]=0; //Motor Elevator at 0 power
}
else if(SensorValue[dgtl6]==1) //While Dgtl6 is active
{
motor[Elevator]=-25; //Motor Elevator at -25 power
wait1000msec(14.2); //Wait 14.2 seconds
motor[Elevator]=0; Motor Elevator at 0 power
}
else if(SensorValue[dgtl5]==1) //While Dgtl5 is active
{
motor[Elevator]=-25; //Motor Elevator at -25 power
wait1000msec(6.1); //Wait 6.1 Seconds
motor[Elevator]=0; //Motor Elevator at 0 power
}
else
{
motor[Elevator]=0; //Motor Elevator at 0 power
}
}
}

I think I’d do it this way (your pick, though).


task main()
{
while (true)
{
if(SensorValue[dgtl2] || SensorValue[dgtl3])
{
motor[Elevator]=25;
wait1Msec(6100);
motor[Elevator]=0;
}
else if(SensorValue[dgtl1])
{
motor[Elevator]=25;
wait1Msec(12200);
motor[Elevator]=0;
}
else if(SensorValue[dgtl4])
{
motor[Elevator] = -25;
wait1Msec(6400); //Is this supposed to be 6.4 secs?
motor[Elevator]=0;
}
else if(SensorValue[dgtl6])
{
motor[Elevator]=-25;
wait1Msec(14200);
motor[Elevator]=0;
}
else if(SensorValue[dgtl5])
{
motor[Elevator]=-25;
wait1Msec(6100);
motor[Elevator]=0;
}
else motor[Elevator] = 0;
}
}

Also, there might be a thing about the ports evaluating to 1 if not pressed and 0 if pressed, I’m not sure. Sorry about the lack of comments, but Vex Forum’s limited line length on iPhone makes them come out weirdly.

I didn’t know you could do that code and /code thing! Thanks!