Translate v5 block code to c++

what is the translated version of the blocks to vexcode v5 text

Motor1.setVelocity(50, velocityUnits::pct);
Motor1.setVelocity(75, velocityUnits::pct);

Think that’s right. Look at the VEX C++ API next time, though, please.

Regretfully, the call to setVelocity() will not run motors, according to the API:

To run the motor a call to Motor1.spin() is required.

It is rarely useful to leave the motor running when no buttons is pressed. Many programs use one button to run in forward direction, another to run in reverse, and when no buttons is pressed to stop the motor.

   if( Controller1.ButtonX.pressing() )
      Motor1.spin(forward, 70, pct); // at 70%
   else if( Controller1.ButtonY.pressing() )
      Motor1.spin(reverse, 50, pct); // at 50%
      Motor1.stop(brake); // or coast or hold

The generated code is part of the V5Blocks file. Just open it with a text editor.

I just threw this together:


And this is in the file:

// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

#include “v5.h”
#include “v5_vcs.h”

using namespace vex;

// Brain should be defined by default
brain Brain;

// Robot configuration code.

//Vision sensor index vars.
int Vision1_objectIndex = 0;

// Generated code.

float my_variable;

int main() {

  // pre event registration
  // register event handlers

  // post event registration
  if (Brain.Screen.pressing()) {
    my_variable = 0.0;
  } else {
    my_variable = my_variable + 1.0;

  return 0;
1 Like