Coding Help

Can someone explain why the motors LeftBackDrive and LeftMiddleDrive don’t run when Button L1 is pressed?
Screen Shot 2019-01-03 at 5.14.00 PM.png

This might be a silly mistake, but you currently have your intake running when button L1 is pressed.

Change the intake.spin command to LeftBackDriveSpin and LeftMiddleDrive and it should work.

I meant when button R1 is pressed lol

No I want the code in the function goToGear to run when R1 is pressed

When R1 is pressed i want it to call the function which then turns the wheels

Okay then. Currently you have:


Change it to this:


I’m not sure if this will fix it, but hopefully it will.

No, it doesn’t, I think the issue is that the function might be getting called many times because I added Brain.Screen.Print to it and it prints something on the brain like 20 times

Can you post the most updated code then?

#include “robot-config.h”

void goToGear(){
LeftMiddleDrive.rotateFor(10, timeUnits::sec);
LeftBackDrive.rotateFor(10, timeUnits::sec);

int main() {
LeftMiddleDrive.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
LeftBackDrive.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
RightMiddleDrive.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);
RightBackDrive.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);

    if(Controller1.ButtonL1.pressing()){ //INTAKE
        Intake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
    else if(Controller1.ButtonL2.pressing()){ //INTAKE
        Intake.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
    else {
        Arm.spin(vex::directionType::fwd, 100, pct);
    else if(Controller1.ButtonDown.pressing()){
        Arm.spin(vex::directionType::rev, 100, pct);
    else {



should be before the while loop, not inside of it. Once you call it it creates a new thread that watches for the button and uses goToGear. I’m not positive about how such a thread would interact with another version of itself, but you may be trying to create an infinite number of identical threads all watching for the same button to be pressed and all trying to do the same thing when they see it, and I know VEXos cannot handle that many threads.

Also, it doesn’t look like you’ve got using namespace vex; in your setup base on your use of vex::… all over the place, but you’re writing timeUnits::sec without vex:: attached to it.

Finally, rotateFor is blocking. Is that what you want? You’ve got it printing to the screen, then running LeftMiddleDrive for 10 s, and when that drive is done you’re running LeftBackDrive for 10 s. If you want them simultaneous, make sure you add the optional waitForCompletion Boolean as false at the end of your first rotateFor call.

Now it’s printing on the brain once, but it is not running the function of the motor

This is the latest function
Screen Shot 2019-01-04 at 1.42.31 PM.png

What does the rest look like now?

I figured it out, it wasn’t working because I also set up a button to run the intake motor so the function wouldn’t run it also