I'm trying to get a temperature from a DS1820 sensor and send it over Virtualwire but something's worng and I don't know what. Below the section with the problem:
First I want to verify if is there anything in the mesg array, but it's empty.
I've checked the output of the "sensors.getTempCByIndex(0)" and it's ok, I get temperature in Celsius degrees in the following format: 21.12
I found the "sprintf" transformation on the internet.
I suspect that he'll want to use a slightly different format:sprintf(mesg, "%d.%03d", wholeTempC, fracTempC);so that the fractional part is zero filled.
I was just looking at the %d format this morning. The page I was looking at said that if the precision value was larger than required to hold the value, it was left filled with 0. I had thought it was left filled with 0, and that the 0 was required to change the left fill character.
I just went back and looked, and saw that I left out the dot. The format specifier should be %.3d. The width comes before the decimal point, and requires the 0 to left fill. The precision comes after the decimal point, and automatically left fills with 0.
It worked.
I made few modifications to fit my needs and now everything it's ok excepting that on subzero temperatures the integer and the decimal has the minus sign in front like this: -12.-24
I think there's a simple workaround for this.
excepting that on subzero temperatures the integer and the decimal has the minus sign in front like this: -12.-24 Smiley
I think there's a simple workaround for this.
Sure. Just use the absolute value of the temperature to compute wholeTempC and fracTempC, then negate wholeTempC if tempC is negative.