Text on V5 Brain

We are trying to print Encoder Values to the brain of the V5 after a button on the remote is pressed. When we press the button to have it print the encoder values on the brain it will print the same line several times and fill the screen. Is there something we have missed in the Code.

For the same of space I left off the drive program. It is a simple tank drive controlled by the Arrow.

void printencoder(void)
{
  Brain.Screen.print("LF ");
  Brain.Screen.print(LFMotor.rotation(vex::rotationUnits::deg));
  Brain.Screen.print( ", RF ");
  Brain.Screen.print(RFMotor.rotation(vex::rotationUnits::deg));
}

void clearencoder(void)
{
  Brain.Screen.newLine();
  LFMotor.resetRotation();
  RFMotor.resetRotation();
}

Controller1.ButtonA.pressed(printencoder);
     Controller1.ButtonX.pressed(clearencoder);

Does it keep printing even after you’re not pressing the button?

Brain.Screen.print will print at whatever the current cursor position is.
Either use setCursor to set the cursor back to wherever you want to print or use printAt to print at a specific pixel location.

1 Like

Thank you jpearman for the advice.

They are okay with where it is printing the first line. The issue is that it will print 8-10 times and it will fill the screen and we cannot see the results for the second time they try and print the encoder values.

try this, see if it does what you want.

#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::motor       LFMotor(vex::PORT1);
vex::motor       RFMotor(vex::PORT2);
vex::controller  Controller1;

void printencoder(void)
{
  Brain.Screen.clearLine( 1, black );
  Brain.Screen.setCursor( 1, 1 );

  Brain.Screen.print("LF ");
  Brain.Screen.print(LFMotor.rotation(vex::rotationUnits::deg));
  Brain.Screen.print( ", RF ");
  Brain.Screen.print(RFMotor.rotation(vex::rotationUnits::deg));
}

void clearencoder(void)
{
  LFMotor.resetRotation();
  RFMotor.resetRotation();
}

int main() {   
    // register events once
    Controller1.ButtonA.pressed(printencoder);
    Controller1.ButtonX.pressed(clearencoder);   

    while(1) {
        LFMotor.spin( fwd, Controller1.Axis3.position(), velocityUnits::pct );
        RFMotor.spin( fwd, Controller1.Axis2.position(), velocityUnits::pct );
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}
1 Like

What does the "using namespace vex; " do?

We would like to be able to print multiple reading to the brain. I will try this solution when we get back to the robot.

it allows access to methods, classes and variables in the vex namespace to be used without needing the vex:: prefix. It’s standard C++ syntax ( although many C++ programmers feel its use is bad practice ). without that statement this line of code

LFMotor.spin( fwd, Controller1.Axis3.position(), velocityUnits::pct );

would need additional vex namespace qualification on some of the parameters

LFMotor.spin( vex::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct );
2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.