View Single Post
  #6   Spotlight this post!  
Unread 22-01-2010, 08:22
Abrakadabra Abrakadabra is offline
Here We Go !!!
AKA: Scott Kukshtel, Mr. K
FRC #3467 (The Windham Windup!)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2002
Location: Windham, New Hampshire
Posts: 159
Abrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant future
Re: Printing Float to Dashboard

Quote:
Originally Posted by Gamer930 View Post
For reference the following code DOES work :-)
Code:
char line_buffer[22];

sprintf(line_buffer, "Y: %.2f", driveController->GetY());
dsLCD->Printf(DriverStationLCD::kUser_Line2, 1, line_buffer);
Thanks for everyones help. Note: just like every language there is 100 ways to do every problem. . . I just really couldn't get anything to work. . . Not saying this is the best way but it works to test out values
That is most definitely NOT the best way to call DriverStationLCD:: Printf(). If you are not careful, you can easily overrun the end of your line_buffer, and most likely corrupt other memory, making for a very hard to debug problem.

The best way is to use the Printf() method as it was intended: put the format string in the argument list, followed by your variable(s):

Code:
dsLCD->Printf(DriverStationLCD::kUser_Line2, 1, "Y: %.2f", driveController->GetY());
If you take a look at the source code for the Printf() method, you will see that it goes to great pains to make sure it does not write more than 21 bytes to its internal line buffer.

HTH.
Reply With Quote