V5: Printing Motor Velocity and Temperature

What’s wrong with this code? I’m trying to print real-time motor velocity and temperature to the brain and velocity to the controller screen but it’s spitting out random numbers that change randomly after “RPM:” and after “Temp:”.
Here is my code:

int flywheelStatDisp(){
Brain.Screen.setFont(vex::fontType::mono40);
while (true){
Controller.Screen.clearLine(3);
Controller.Screen.setCursor(3,0);
Controller.Screen.print(“RPM:%d”,flywheel.velocity(vex::velocityUnits::rpm));

    Brain.Screen.clearScreen();
    Brain.Screen.printAt(1,40,"RPM:%d",flywheel.velocity(vex::velocityUnits::rpm));
    Brain.Screen.printAt(1,80,"Temp:%d",flywheel.temperature(vex::percentUnits::pct));
    Brain.Screen.render();
    vex::task::sleep(20);
}

}

1 Like

Both


velocity

and


temperature

return


double

values.


%d

is the format character for


int

values. Try


%f

instead.

2 Likes

It worked. Thank you so much. Is there a function that can truncate the numbers tho.

Multiply by some power of 10, round it off, then divide by the same power of 10. Print that result. Usually works. Most print format strings don’t have rounding specifiers built in.

1 Like

you can limit the number of decimal places shown like this

Brain.Screen.printAt(1,40,"RPM: %8.3f",flywheel.velocity(vex::velocityUnits::rpm));

1 Like

Thank you.

What do those crazy number number and letter combinations even mean you ask! Well wonder no more: www.cplusplus.com/reference/cstdio/printf/

This is kinda off-topic but…

@goofnrox why in the world is there an uppercase decimal point, especially when the lowercase one looks exactly the same?

Because floating point numbers include items like “INF” for infinity and “NAN” for not-a-number, which can be printed in upper or lower case.

Brain.Screen.Print does not support the complete list of formats shown, only the most common ones. however, using the standard library sprintf to create a string should.

1 Like