How to display joystick values on V5 brain?

I want to display the joystick values onto the V5 brain, but my abyssal lack of understanding of C++ and the various V5 classes is confounding my efforts. Any suggestions?

The general idea is this, but the compiler ain’t buying it…

   
//Trying to display the joystick values on the Brain...
      int JoystickAxis3 = (vex::Controller1.Axis3.value(), vex::velocityUnits::pct);
      Brain.Screen.printAt( 50,  150, "Axis3", JoystickAxis3);

1 Like

The Controller (formerly joystick in the Cortex world) is just another sensor. Take a look at this forum post. It includes C++ examples, as well as Python and Blockly.

The PROS API may be more familiar to you. Example code for writing a joystick value to the LCD screen would be as follows:


void opcontrol() {
  pros::Controller master (CONTROLLER_MASTER);

  while (true) {
    // Print to the 0th line of the emulated LCD screen
    pros::lcd::print(0, "Joystick val: %d", master.get_analog(ANALOG_RIGHT_Y));
    
    pros::delay(20);
  }
}

This will bring up a screen on the V5 brain that looks and acts very much like the LCD screen used with the cortex.

OK, I’ll have a closer look at this. At first glance, I thought this might be a Robot Mesh-only kind of set-up. Between the kids using RobotC, PROS, VCS, and you-name-it, I’m having a hard time keeping track of what to do.

Robot Mesh C++ uses the standard VEX API calls. It should be pretty close to other programming options (in C++, not ROBOTC).

If you’re more used to using C, the PROS C API has all of the same functionality as its C++ API. You could easily write the above C++ example in C as follows:


void opcontrol() {
  while (true) {
    // Print to the 0th line of the emulated LCD screen
    lcd_print(0, "Joystick val: %d", controller_get_analog(CONTROLLER_MASTER, ANALOG_RIGHT_Y));
    
    delay(20);
  }
}

I think the correct way to do this in VCS according to the documentation is standard formatstring stuff:


//Trying to display the joystick values on the Brain...
int JoystickAxis3 = (vex::Controller1.Axis3.value(), vex::velocityUnits::pct);
Brain.Screen.printAt( 50,  150, "Axis3: %d", JoystickAxis3);


%d

is the format specifier for integers.

if Controller1 is your instance of a vex::controller. Then read axis value and display like this.


 int JoystickAxis3 = Controller1.Axis3.value();
 Brain.Screen.printAt( 50,  150, "Axis3: %d", JoystickAxis3);

v5 looks complicated

It really isn’t. Look at the examples @jbayless posted. It couldn’t be any simpler for the cortex in any language.

Thanks everyone. I got it working. Time for me to actually learn C++.