Problem with coding Macro

So I have a simple macro and when I click the button that activates the macro nothing happens. Is there something wrong with my code.

And also I wanted to know if there is a way to make the macro so that when the button is clicked, the tilter goes up -.05 rotations and then depending on how long I hold the button the tray will move.

  • the tray and lift are inverted so that’s why they have a negative sign there.

      void driverMacros() {
        Tilter.setVelocity(100, vex::velocityUnits::pct);
        Tilter.rotateFor(-0.5, vex::rotationUnits::rev);
        vex::task::sleep(250);
        Lift.setVelocity(100, vex::velocityUnits::pct);
        Lift.rotateFor(-0.78, vex::rotationUnits::rev);
      }
    

void usercontrol(void) {
  Controller1.ButtonX.pressed( driverMacros );
  // User control code here, inside the loop
// User control code here, inside the loop
while (1) {
}

It seems like your doing this in a competition template, so you would have to put “Controller1.ButtonX.pressed( driverMacros );” inside the while loop.

Controller1.ButtonX.pressed( driverMacros ); should not be inside the while.
look here for general info on callbacks:

and here for not in while loop:

1 Like

I’m not sure if this is best practice, but I would have done:
(also make sure to put a sleep statement in your loops)

void driverMacros() {
    Tilter.setVelocity(100, vex::velocityUnits::pct);
    Tilter.rotateFor(-0.5, vex::rotationUnits::rev);
    vex::task::sleep(250);
    Lift.setVelocity(100, vex::velocityUnits::pct);
    Lift.rotateFor(-0.78, vex::rotationUnits::rev);
  }//close macro

void usercontrol(void) {
      while (1) {
        if (Controller1.ButtonX.pressing()) {
          driverMacros();
        }//close if
       wait(10, msec);
      }//close loop
    }//close usercontrol
1 Like