View Single Post
  #2   Spotlight this post!  
Unread 21-01-2010, 20:07
TheDominis TheDominis is offline
Registered User
FRC #2152
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Port Orange, Florida
Posts: 88
TheDominis has a spectacular aura aboutTheDominis has a spectacular aura about
Re: Printing Float to Dashboard

Quote:
Originally Posted by Gamer930 View Post
I'm looking at printing the value of the joystick y axis to the screen.

Code:
DriverStation *ds;
DriverStationLCD *dsLCD;
Joystick *driveController;

RobotDemo(void)
{
    ds = DriverStation::GetInstance();
    dsLCD = DriverStationLCD::GetInstance();
    driveController = new Joystick(1);
}

void OperatorControl(void)
{
    GetWatchdog().SetEnabled(true);
    while (IsOperatorControl())
    {
        GetWatchdog().Feed();
        dsLCD->Printf(DriverStationLCD::kUser_Line4, 1, driveController->GetY());
        dsLCD->UpdateLCD();
    }
}
Is there something that needs to be included?? is there a ToString() like there is in java???

Also is there string concatenation that you can add two strings together?? "Left Drive: " + driverController->GetY()
Your ToString() comment made my day.

If you want to write a float to a string you can use some of the following methods.

Code:
float my_float = 123.456f;
char line_buffer[22];
sprintf(line_buffer, "value: %.2f", my_float);

// or

#include <sstream>

float my_float = 123.456f;
std::stringstream ss("value: ");
ss.precision(2);
ss << my_float;
std::string line_buffer = ss.str();
Reply With Quote