When button pressed callback help needed

//flywheelfix
    if(Controller1.ButtonUp.pressed()){
      flywheel.spin(forward);
    }
    if(Controller1.ButtonDown.pressed()){
      flywheel.stop();
    }

image

So, I want to make it so that when the controller button up is pressed, it runs our flywheel motor until down is pressed. However, it keeps giving me the “too few arguments to function call, single argument ‘callback’ was not specified” error. I have checked many posts asking about this, and I do not understand any of the answers, so please do not link other forum posts/questions, and directly respond in a way that I (C++ V5 only, first year) could understand.

You should use pressing()

    if(Controller1.ButtonUp.pressing()){
      flywheel.spin(forward);
    }
    if(Controller1.ButtonDown.pressing()){
      flywheel.stop();
    }

Take a look at this response: Toggle in vexcode pro - #6 by Hudsonville_Robotics

1 Like

I know I should use pressing. That’s the default for the controller, too. I took it off of the controller SPECIFICALLY so that I could use “pressed”. I want to make it so that the driver doesn’t have to hold down the button every time they shoot.

Also, the resource you linked is for Vexcode Pro, which I do not have access to.

pressing() returns the current state of the button, is the user “pressing” the button or not.

pressed() is used to register an event handler, that is, a function that will be executed every time the user presses the button. When the button is “pressed” call this function.

It all depends on which style of programming you want to use as to which you choose.

There is no API to configure the button as a toggle button that changes state each time you press it, that’s code you need to write yourself.

APIs are all the same.

5 Likes

Button Up will start it and keep it running until Button Down is pressed - unless you have other code that makes changes to the motor.

If this isn’t your expectation, then we need more explanation.

1 Like