Trying to program a vex intake i am new to c++ but know some things

i have tried a few things to get it to work but i just need to start over and go from scratch

if you can help me i need two motors to spin forward while the R1 button is held down when released they stop

1 Like

Just some pseudocode, I’m sure you can figure out the actual commands after a quick search on the API:

if(Controller button is pressing){
   Spin intakes
}

else{
   Stop intakes
}
6 Likes

is there any way to do it with the name of the motor (intake1 and 2)

This is for the intakes to move forward, It creates a loop that is constantly checking if the specific button is being pressed, and if it is, it will carry out the action that is in the brackets.

if(Controller1. buttonR1.pressing){
spin.(intake1, 100, pct);
spin.(intake2, 100, pct);
}
else{
(stop::intake1);
(stop::intake2);
}

This is the code to make them go reversed, it is just on a separate button and the speed values are reversed.

if(Controller1. buttonR2.pressing){
spin.(intake1, -100, pct);
spin.(intake2, -100, pct);
}
else{
(stop::intake1);
(stop::intake2);
}

hope this helps!

4 Likes

thank you so much your a life saver

1 Like

I think that the stop is right, if it is not, try

stop.(intake1)
1 Like

the bolded code is highlighted red in the program
i guess something’s wrong don’t know what

if(Controller1.ButtonR1.pressing){

spin.(intake1, 100, pct);
spin.(intake2, 100, pct);

}

else{

(stop::intake1);

(stop::intake2);

}

Well you see, that seems like pseudocode. It isn’t the actual code, but it contains the logic within the code. You think through it and think about what motors you would need to start and stop.

I don’t know what the actual vex v5 api looks like so i could be wrong, but it seems weird to have an object named ‘spin’.

1 Like

oh ok

i have seen a bunch of stuff say pseudocode, what does it mean?

You have to look at some sort of documentation, which says what functions do what.

1 Like

spin is right, it is odd though. And I was just going off hte top of my head, so the stop is most likely wrong

1 Like

what does the pct mean does that mean percent?

Taken directly from the Vex Api linked and mentioned above,

you have three options when it comes to velocity. I don’t think anyone really uses dps because it is the same as rpm essentially,

1 Like

sorry, I screwed up the code. this is correct I think
(maybe)

if(Controller1. buttonR2.pressing()){
spin.(intake1, 100, pct);
spin.(intake2, 100, pct);
}
else{
intake1.stop(vex::brakeType::hold);
intake2.stop(vex::brakeType::hold);
}
2 Likes

Vexcode also has a thing where you can get exact pieces of text that are right. Just look for the ones that look like they should do the same thing as what I have put here.

1 Like

That’s not the correct syntax for vexcode. To spin a motor, you say something like:

Motor.spin( fwd, 100, pct );

To stop a motor, you say:

Motor.stop();

I recommend you check out the API: http://help.vexcodingstudio.com/#pro
(This is the VCS API, which is basically the same as Vexcode. There might be a newer version of this though, I’m not sure)

Hope this helps :slight_smile:

9 Likes

https://api.vexcode.cloud/v5/html/

9 Likes

:man_facepalming: totally screwed that one up, didn’t I?
image
this is right. I can’t believe I messed it up that bad. Sorry @glazebaize

2 Likes

where it says mars, you would put your controller name.

1 Like

Thanks so much I will use this asap