NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Temperature Project Code explaination
December 29, 2009 by markjbenson |
Hi All, Just got my nerdkit for xmas - been playing a bit with the temperature project so it displays F, C & mV but my c programming is 10 years rusty so could anyone explain what the %.2f is for me? This works...
...but I was looking for a way to output both f & C on the serial in one line and realised I didn't understand the syntax. I suppose I should really try this first but I have spent long enough on this thing today so will try tomorrow. Would this work? printf_P(PSTR("%.2f degrees F or %.2f degrees C rn"), temp_avg, temp_cent); Thanks, Mark |
---|---|
December 29, 2009 by hevans (NerdKits Staff) |
Hi Mark, Your thinking is definitely right, you can define a single format string with more than one place holder to be replaced by a formatted variable. However the problem there is going to be that you only have 20 characters in one line of the LCD. The line as you have it will overflow to a different line, which is probably not what you want. Check out our printf and scanf tutorial for a fairly comprehensive explanation of the topic. Humberto |
December 30, 2009 by markjbenson |
Right - the %f is the variable substitution and the .2 within that is the formatting or precision of the string (i.e. the number of trailing digits after the decimal point). All makes sense. I was outputting the Temperature to the serial port so wasn't worried about length. Thanks for the tutorial - very helpful. |
Please log in to post a reply.
Did you know that Morse code is a compact way to transmit human-readable text over binary channels? Learn more...
|