Programming Controller Question

So one of my teams has a conveyer system and they are trying to program the F Up button to start the conveyer and keep it going forever till another button is pressed, such as F down or E down. Then they want to be able to press F up again to start the conveyer. However no combo they seem to be trying in VexCode is working. Either it only stops it temporarily or the motor start to fight itself between continuing to move and stopping which has me concerned it will burn up the motor.
Any help is appreciated.

I’m not participating in Vex IQ, so my response may be wrong, but I would have it so that when the button is pressed, it spins the motor, then enters a while loop that breaks when one of the other buttons is pressed. The motor could then be set to stop in an else after the initial if.

Try using a Callback command.

if (Controller1.ButtonUp.pressed(Function)

I think this might work. I am still a beginner however, so im not postitive.

Sorry i couldn’t be of more help!

Are you using VexIQ Blocks/ Can you a sample of some of the code that hasn’t worked?

Are you trying to run though motor both from the set up function and in a program?

Yes on VEX Blocks. Tried to do a “When controller button pressed, set conveyer forward, repeat forever”. Then trying to add another command line to stop that when another button is pressed. But when you hit the other button, it does stop it momentarily but as soon as you let go the conveyer kicks back in.

I’m no expert, but maybe this would work…

When (first button) pressed
spin (conveyor Motor) Forward
Wait until (some other button) pressed
Stop (conveyor motor)

Have the button change a variable from on/off. Then have the motor run based on the value of the variable.

We don’t use VEXCode IQ Blocks, but I think you can do something like this

task main()
		if (vexRT[BtnFUp] == 1)
			setMotorSpeed(conveyor, 100);
		if (vexRT[BtnFDown] == 1)
			setMotorSpeed(conveyor, 0);


Here is a basic implementation:

27 PM

Hope it’s helpful! Good luck!


You can do something similar on one button with code that goes something like.

When Controller F Up Pressed
If(runConveyor = True)
Set runConveyor to False
Set runConveyor to True

This will allow the F up to toggle between True and False and then your forever loop on the left side of the above code will pick it up

1 Like

Thanks so much for the help. He got the conveyer to run forward. However, when he tries to reverse it now using button E down the motor wants to fight itself and not just let it go, it is zigzagging between forward and reverse. Any new tips? =)

The issue is that in Sarge’s code you are doing

If F Up then
Forward (true)
Stop (false)

and I’ve bet you’ve added
If E down then
reverse (true)
stop (false)

So when you bang that together you have
If F up then
if E down then

So the brain goes from UP - Stop or Stop - Reverse, that causes the stutter you are seeing.

You want code that says

If F UP then
forward else
If F Down then

The issue is using the buttons as events.

(Sorry, I’m not near a computer with the blocks on them. )

Stealing @spaghetti_code code and adding to it.

task main() { 
while(1==1) { 
   if (vexRT[BtnFUp] == 1) { 
         setMotorSpeed(conveyor, 100); }  // snork the ball up
   else if (vexRT[BtnFDown] == 1) {
        setMotorSpeed(conveyor, -100); }  // spit the ball out 
   else {
        setMotorSpeed(coveyor, 0); } // stop

Note that the drive base code is missing, so if you do just this the balls will move, but the base will just sit there.

1 Like

Thanks, @Foster! Although, I think with your nested if/elseif the conveyor will stop shortly after either BtnFUp or BtnFDown are released. :slight_smile: The else at the end is the default when either BtnFUp or BtnFDown are not being pressed.

@Mark.Morey do you want a button for forward (BtnFUp), button for reverse (BtnFDown), and one for Stop (BtnEDown)? Then, I would recommend what Foster wrote, but taking the setMotorSpeed(conveyor, 0); to a separate if statement for BtnEDown. BTW, this is the same code that my son’s robot has. Conveyor with BtnFUp forward, BtnFDown revers, BtnEDown stop.

Can you post your code (I don’t think your motors are reversed since it works fine going forward)? The code I posted should work as it’s very similar to what my son’s team has on their robot.

1 Like

Yes, I try to teach the roboteers that with fingers off the controller the robot completely stops. Referees hate it when they say 3-2-1 stop, controllers down and parts of the robot continues to move. The code that I showed has the conveyor stopping with fingers off.

1 Like

Ahh. Again, there are multiple ways to do this, but if you need to also reverse the conveyor, this might be the simplest method:

07 PM

@Foster - I can understand that, but if you have an intake conveyor that you want to run for almost the entire match, it isn’t practical to expect the kids to drive the entire match while holding down a button. Especially F-up, which would tie up their right thumb so they couldn’t use the right joystick. There is definitely a place for toggling on and off.

I would suggest that you have the students walk though their own code, block by block so they understand exactly what the robot is being programmed to do at each moment. If they take their time, and remember that each if statement they have will execute just one of the options, and that the program overall is executing extremely fast, they will begin to understand what is happening with their robot and code. It can be helpful to have students run a very simple program that has a loop and a single variable that increments by 1 each time through the loop (ie i = i + 1) you could also print the current or elapsed time. Then run the program and look at the results. Its amazing to seen how fast a loop runs without pauses. Kids often dont get that until they see it.

The process of walking through their code step by step will serve them well in all programming they do.


@Sarge, a good point. Then the discussion with the team would be how do you want to drive the robot. I don’t know what your teams setup is. We have a tendency to use the joysticks and the front buttons to drive, move things around to score points. The E and F are used to trigger presets, like lifting the cube to the height to score on the goals.

1 Like

If you’d rather not have to hold down the buttons, you could do this:

16 PM