Cortex print issue

I was trying to print the motor rotations and Battery capacity to the cortex. However, there is a small problem that is annoying me a bit. here is the code:

Blockquote

#include “vex.h”
#include “user/pragma.h”
#include “user/motor_config.h”

// shows battery left, chassis motor rotation
// used for auton mainly / debug

void GUI_set_up()
{
Brain.Screen.setFillColor(black);
Brain.Screen.setPenColor (white);
Brain.Screen.setFont (propM);
Brain.Screen.setPenWidth (20);
}

void basic_info()
{
GUI_set_up();
Brain.Screen.setCursor(1,1);
Brain.Screen.print(“Battery: %d%”, Brain.Battery.capacity());
Brain.Screen.setCursor(3,1);
Brain.Screen.print(“Rightfront: %d”, rotate(rightfront));
Brain.Screen.setCursor(5,1);
Brain.Screen.print(“RightBack: %d”, rotate(rightback));
Brain.Screen.setCursor(7,1);
Brain.Screen.print(“LeftFront: %d”, rotate(leftfront));
Brain.Screen.setCursor(9,1);
Brain.Screen.print(“LeftBack: %d”, rotate(leftback));
Brain.Screen.render();
}

The basic idea is to print
Battery: value
Right front: value
Right back: value
Left front: value
Left back: value

Blockquote

However, when there is a digit change in the value it does not remove the last digit.
For example, if the previous rotation value for the right front was 1245 and it changes to 800, it somehow prints 8005 which is very confusing.

Simply put, use the clearScreen function to clear the screen at the end of each loop. You are just writing over the previous text.

Edited to add:

https://api.vexcode.cloud/v5/html/classvex_1_1brain_1_1lcd.html#a76ae80555c4ceaee53eea377d07a0d09

Found the API reference!

You could also use the clearLine command, which would clear the rest of the line you are on. You could probably integrate that into your code easily by saying

Brain.Screen.setCursor(1,1);
Brain.Screen.clearLine();
Brain.Screen.print(“Battery: %d%”, Brain.Battery.capacity());

And so forth.

Code Formatting

To format your code nicely in a box like I did, you can do ``` before and after the code to format.

4 Likes

Thank you so much! It worked for me without problem!

1 Like