|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
printf question..... |
Posted: Thu Jan 03, 2008 5:26 pm |
|
|
Hi all,
I have a line of code that outputs two temperatures to an LCD as follows:
Code: |
fprintf(LCD, "1: %lu F 2: %lu F", Temp[0], Temp[1]);
|
Before this code, I test Temp[0] and Temp[1] to be sure they are each in the appropriate range, and their respective sensor has not become disconnected. If a disconnect is detected, I'd like to replace the temperature value with '--' or 'NC' or something like that to flag the user. The problem is how to do this with printf that is setup for numeric data? The data type must be specified and it's a numeric value, not some ASCII text. I can do this with lots of kludgy code, but was wondering if there is a neat and clean way to accomplish it?
Thanks!
Dave |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 03, 2008 5:48 pm |
|
|
I don't think there exists a very elegant solution and you will always come to a variation of the code below: Code: | if Sensor1Disconnected
fprintf(LCD, "1: NC ");
else
fprintf(LCD, "1: %lu F", Temp[0]);
if Sensor2Disconnected
fprintf(LCD, " 2: NC ");
else
fprintf(LCD, " 2: %lu F", Temp[1]); |
|
|
|
Guest
|
|
Posted: Tue Jan 08, 2008 10:52 am |
|
|
Hi All,
OK, a related question:
I want to insert the degree symbol into the data that is displayed on the LCD. Here is what I am sending to the serial LCD now:
Code: |
fprintf(LCD, "1: %lu F", Temp[0]);
|
I know that the degree symbol exists in the character set of the LCD display, and I can display it by itself using:
My question is how do I put everything in the same line? If I break the line up into multiple statements, I can't get it to compile
Thanks,
Dave |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 08, 2008 11:11 am |
|
|
Code: |
#define DEGREE 0xDF
fprintf(LCD, "1: %lu %cF", Temp[0],DEGREE);
|
You can also include it directly, with:
Code: |
fprintf(LCD, "1: %lu \xDFF", Temp[0);
|
Best Wishes |
|
|
Guest
|
|
Posted: Tue Jan 08, 2008 11:44 am |
|
|
Ttelmah,
Great! Works like a charm! Thanks for the tip!
Dave |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|