VEX code Blocks

Have a bumper switch to limit the movement of the arm in the down direction when L2 is pressed otherwise want L1 to run arm up. This seems simple enough. Can’t get it to work in Blocks. Here is a screenshot of what I have.

image

What is happening in your code is, if the limit switch is pressed then the arm will stop and the code will wait until L1 is pressed, at which point it will tell the arm to move up, and then loop back to the if statement. The limit switch will still be pressed since code runs fast and it will then tell the motor to stop, and so on.

From what I can understand you want L1 to move the arm up, L2 to move the arm down, but allow you want the arm to stop if it hits the limit switch (which happens when moving down). Am I correct?

To achieve this would want an if block checking that L2 is pressed and that the limit switch is not pressed (inside the block you spin the arm down). Then you want an else if block checking that L1 is pressed (inside the block you spin the arm up). Finally you want an else block, inside of which you put a stop arm.

Also, when writing user controls I would recommend not to use waits because then the rest of your controls wouldn’t be able to do anything.

2 Likes

Like this? the armLimit still doesn’t cut the motor off when L2 is pressed and the armLimit is pressed.

image

Two things:

Put a “not” in front of the “armlimit is pressed?”

The second if should be in the “else” part of the first if (which needs to be replaced with an if…else).

1 Like

I guess what I’m struggling with is in Blocks I don’t see just an Else stmt and I don’t see an Else-If. These are the only blocks available. Just an If-else.

I know I need to specify a

If Btn L1 =1
{ Arm up}

else if L2 = 1 and Arm Limit = 0
{Arm down}

else
{ Arm stop}
I’ve programmed this in text before but I’m struggling with what blocks to use.

image

image

This is the same as:
if() {}
elseif() {}
elseif() {}
else {}

1 Like

OK I’m close I think. Suspect I’m not using the not stmt corrrectly
This code doesn’t allow it to go down at all.
And thank you for all the help.

1 Like

Code looks fine to me…

A few questions:

  1. When you push L1 what happens?
  2. When you push L2 and the bumper is pressed what happens?
  3. When you push L2 and the bumper is NOT pressed what happens?
  4. Have you tested the bumper to be sure it’s working?
1 Like

It seems to be a defective bumper switch, one of the new ones that come with the V5 claw bot kit. It never occurred to me to check a new switch. With the V5 bumper L2 didn’t run at all. I put an older EDR limit switch on it and it worked? Is there something that we have to do differently with the new bumper switches?

1 Like

I see now that a student had shorted out the switch by pinching the wire in the keps mounting nut. Gads :face_with_raised_eyebrow:

2 Likes