Trying to use oF and oC on my display...

Do you have a question on how to do something.
Ask in here.
Post Reply
sjmusic2
Posts: 33
Joined: Sun Sep 25, 2011 8:25 pm

Trying to use oF and oC on my display...

Post by sjmusic2 »

I am trying to include temp probe data converted to oC in addition to my oF already displayed and it feels like it should be very easy but I can't seem to figure it out !

Code: Select all

int T2C;
float T2C2;

void DrawCustomMain()
{
T2C=ReefAngel.Params.Temp2;
T2C2=((float)T2C-32.0)*0.56;
ConvertNumToString(text, T2C2, 10);
ReefAngel.LCD.DrawText(T2TempColor,DefaultBGColor, 95, 65, T2C2);
}
Thanks in advance.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Trying to use oF and oC on my display...

Post by binder »

If you are using 0.9.X libraries, you have to use this:

Code: Select all

ReefAngel.Params.Temp[T2_PROBE];
This is what we use when we convert from C to F initially:

Code: Select all

Temp = Temp * 1.8 + 320;
You also must remember that the value stored in the Temp variable does not contain a decimal point. So 80.0 is actually stored as 800. You code would need to look like this:

Code: Select all

T2C2 = ((float)T2C-320)*0.56;
It may need to be tweaked a little more, but that should get you going.
sjmusic2
Posts: 33
Joined: Sun Sep 25, 2011 8:25 pm

Re: Trying to use oF and oC on my display...

Post by sjmusic2 »

I'm not using 0.9 yet, so this is where I ended up...just posting for reference (I added a degree graphic with PutPixel as I'm unaware of a font charcter already in existance) :

Code: Select all

int T2C;
int T2C2;

//This is inserted into DrawCustomMain...

//Convert and display LED array in Celsius
T2C=ReefAngel.Params.Temp2;
T2C2=((float)T2C-320)*0.56;
ConvertNumToString(text, T2C2, 10);
ReefAngel.LCD.DrawText(COLOR_OLIVEDRAB,DefaultBGColor, 95, 79, text);
ReefAngel.LCD.DrawText(COLOR_OLIVEDRAB,DefaultBGColor, 70, 79, "C");
ReefAngel.LCD.PutPixel(70, 66, 79);
ReefAngel.LCD.PutPixel(70, 67, 79);
ReefAngel.LCD.PutPixel(70, 65, 80);
ReefAngel.LCD.PutPixel(70, 65, 81);
ReefAngel.LCD.PutPixel(70, 66, 82);
ReefAngel.LCD.PutPixel(70, 67, 82);
ReefAngel.LCD.PutPixel(70, 68, 80);
ReefAngel.LCD.PutPixel(70, 68, 81);

I could probably have done the conversion in one step to save code, but I have plenty of free space so I made it easier to read instead :)
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Trying to use oF and oC on my display...

Post by binder »

I forgot I had this stuff inside the libraries...

Code: Select all

#define CONVERT_TO_C(x)	((x) - 320)/1.8
#define CONVERT_TO_F(x)	((x) * 1.8) + 320
it could be simplified or changed so there's no division being performed, but still.
You could then use:

Code: Select all

T2C2 = CONVERT_TO_C(ReefAngel.Params.Temp2);
Then the compiler would handle all the code behind the scenes.
sjmusic2
Posts: 33
Joined: Sun Sep 25, 2011 8:25 pm

Re: Trying to use oF and oC on my display...

Post by sjmusic2 »

Just saw this new info, thanks, every byte saved is much appreciated :)
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Trying to use oF and oC on my display...

Post by binder »

sjmusic2 wrote:Just saw this new info, thanks, every byte saved is much appreciated :)
Cool. :)
Post Reply