![]() |
printf() syntax and parameters
I've been looking at using the printf() function to display joystick values, but I'm a little confused about the proper syntax and parameter usage to make the code work. I want to do the following:
Result text in IO: X 126 Y 250 (Where 126 is the value of p1_x and 250 is the value of p1_y) Could anyone enlighten me on this issue? |
Re: printf() syntax and parameters
Quote:
printf("X %d Y %d\n", p1_x, p1_y); |
Re: printf() syntax and parameters
Quote:
http://www.ifirobotics.com/dashboard_viewer.shtml you plug your OI to your computuer's serial port and it displays a lot of different inputs such as joysticks,buttons,etc |
Re: printf() syntax and parameters
Maybe this is a holdover from the older version of printf(), but I've always been careful to cast (convert) any "char" types (one byte numbers) to "int" type (two byte numbers on the RC) like this:
Code:
printf( x value: %d, y value: %d\n\r", (int)XAXIS, (int)YAXIS );Here's the quick story about printf() on any system: printf takes a variable number of arguments. The first one must be there and it must be a string. It's called the "format string". That string can have anything in it. You put a '%d' each place where you want it to print a value. For each %d in the format string there must be a matching argument after the format string. They are matched up in the order the %d's appear in the format string. You don't have to have any %d's. Then you are just printing a message that's always the same: Code:
printf( "Starting autonomous...\n\r" );Use %d when you want to print an int type. There are other ones, like %f for "float" types, but if you avoid using floats on the robot controller (and you should avoid using floats) then you won't have a need for %f. |
Re: printf() syntax and parameters
Typecasting your arguments is a good practice to follow.
%f is not supported by this printf. %ld might be a better example. You can find full excruciating details in the MPLAB_C18_Libraries document that came on the CBot CD in the Kit-of-Parts. |
| All times are GMT -5. The time now is 13:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi