Go to Post My nagging fear is that I'm a programming dinosaur, stuck in a procedural tar pit and doomed to extinction as the dataflow mammals take over. - Alan Anderson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-01-2008, 23:06
compwiz2008's Avatar
compwiz2008 compwiz2008 is offline
Registered User
FRC #2139
 
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 11
compwiz2008 is an unknown quantity at this point
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?
  #2   Spotlight this post!  
Unread 17-01-2008, 23:39
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,721
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: printf() syntax and parameters

Quote:
Originally Posted by compwiz2008 View Post
X 126 Y 250 (Where 126 is the value of p1_x and 250 is the value of p1_y)
#include <stdio.h>



printf("X %d Y %d\n", p1_x, p1_y);
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 18-01-2008 at 18:33. Reason: Dyslexic slash
  #3   Spotlight this post!  
Unread 17-01-2008, 23:42
mormannoob's Avatar
mormannoob mormannoob is offline
President and Senior Programmer
AKA: Clinton
FRC #0498 (Cobra Commanders)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Glendale,AZ
Posts: 93
mormannoob is on a distinguished road
Re: printf() syntax and parameters

Quote:
Originally Posted by compwiz2008 View Post
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?
why dont you try ifi dashboard
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
__________________
Why cant code work the first time

Wait I have to lead programmers thats like asking a kid who doesnt know how to ride a bike to lead a group of guys at the tour de france
  #4   Spotlight this post!  
Unread 18-01-2008, 13:57
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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 );
Otherwise you can get some huge, crazy values printing out.

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" );
Note the \n and \r. These make it go to a new line. The FRC printf() wants to see \r (I'm not clear on why) but in the rest of the world you would just use a \n ("newline"). Using both makes it work in all cases.

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.
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #5   Spotlight this post!  
Unread 18-01-2008, 18:36
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,721
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
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.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 18-01-2008 at 18:45.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error: externs, structs, and macros Astronouth7303 Programming 3 16-02-2005 15:39
Default Code and printf WilsonDJ00 Programming 2 22-01-2005 16:39
printf and newlines Jeff McCune Programming 5 21-02-2004 21:09
printf isn't printf-ing. Help! Meandmyself Programming 14 15-02-2004 16:27


All times are GMT -5. The time now is 09:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi