One button start, One button stop (C++)

Here, a couple of examples for you. Obviously move most of the code into usercontrol, except leave the event registration in main if you go that route.

This one using the button pressing() API, it detects the release to press transition.

example using pressing and state flags
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      2/16/2023, 8:38:46 PM                                     */
/*    Description:  EXP project                                               */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "vex.h"

using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;

// define your global instances of motors and other devices here
vex::controller  Controller1;
vex::motor       m1(PORT1);

int main() {
    bool bButtonLast = false;
    bool bButtonState = false;

    while(1) {
        bool bButton = Controller1.ButtonB.pressing();

        // look for release to press transition  
        if( bButton && !bButtonLast ) {
          if( !bButtonState ) {
            bButtonState = true;
            m1.spin(forward, 50, rpm );
          }
          else {
            bButtonState = false;
            m1.stop();
          }
        }
        // save current button state        
        bButtonLast = bButton;


        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}

This one uses an event handler.

example using pressed callback
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      2/16/2023, 8:38:46 PM                                     */
/*    Description:  EXP project                                               */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "vex.h"

using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;

// define your global instances of motors and other devices here
vex::controller  Controller1;
vex::motor       m1(PORT1);

void buttonHandler() {
    static bool bButtonState = false;

    if( !bButtonState ) {
      bButtonState = true;
      m1.spin(forward, 50, rpm );
    }
    else {
      bButtonState = false;
      m1.stop();
    }
}

int main() {
    Controller1.ButtonB.pressed( buttonHandler );

    while(1) {
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}

and finally, this is how the special PRESSED API would be used.

This API was originally created for the block coding in the, now obsolete, vex coding studio application. It more or less does what my first example above does, that is, tracks the state of the button and reports if a released to press change has occurred since it was last called, once called the internal flag will be cleared. The advantage is this is happening inside vexos using the same code that also handles the conventional event handling.

undocumented PRESSED
int main() {
    bool bButtonState = false;

    while(1) {
        // look for special PRESSED event state
        if( Controller1.ButtonB.PRESSED ) {
          if( !bButtonState ) {
            bButtonState = true;
            m1.spin(forward, 50, rpm );
          }
          else {
            bButtonState = false;
            m1.stop();
          }
        }

        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}