what is the translated version of the blocks to vexcode v5 text
if(Controller1.ButtonX.pressed())
{
Motor1.setVelocity(50, velocityUnits::pct);
}
else
{
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:
https://api.vexcode.cloud/v5/html/classvex_1_1motor.html#a01c6e16373f5a03f138af1fe22e21f3e
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%
}
else
{
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() {
srand(vex::timer::system());
// pre event registration
// register event handlers
task::sleep(15);
// post event registration
Brain.Screen.print(“Hello”);
if (Brain.Screen.pressing()) {
my_variable = 0.0;
} else {
my_variable = my_variable + 1.0;
}
return 0;