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.
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.
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.
#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);
}
}
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