0

simplifying a formula
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

simplifying a formula

by mjpcarbon on Sat Mar 15, 2014 5:26 pm

Me again I would like to simplify a small formula to keep a sketch clean but once again cannot accomplish it

I would like this be be true Serial.print((objt * 1.8 )+32) = objta;

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

by adafruit_support_bill on Sat Mar 15, 2014 5:32 pm

Not sure what you are trying to accomplish there. Maybe if you showed us the relevant parts of what you have now for context.

adafruit_support_bill
 
Posts: 81533
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

by adafruit_support_mike on Sat Mar 15, 2014 11:47 pm

It looks like you're trying to do a Celsius-to-Farenheit conversion, but as you've written the statement you're trying to assign a value to the function Serial.print().

Is this closer to what you wanted?

Code: Select all | TOGGLE FULL SIZE
objta = ( objt * 1.8 ) + 32;
Serial.print( objta );
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 63053
Joined: Thu Feb 11, 2010 2:51 pm

Re: simplifying a formula

by mjpcarbon on Sun Mar 16, 2014 11:46 am

Yes that works like I wanted. again thank you
One curious thing, by doing this I lost the 2 decimal places in Serial Monitor( it doesnt matter but I am curious why)

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

by adafruit_support_bill on Sun Mar 16, 2014 12:55 pm

What are the data types of the variables involved?

adafruit_support_bill
 
Posts: 81533
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

by mjpcarbon on Sun Mar 16, 2014 6:29 pm

Bill when you say variable, I am unsure of what you mean.
The tmp006 is reading temp and works great, just curious when I added the
Code: Select all | TOGGLE FULL SIZE
objta = ( objt * 1.8 ) + 32;
Serial.print( objta );
I lost the decimal places. Again it doesnt matter I just wanted to know why

I am also excited to receive the LCD screen I just ordered to see if I can display the temp

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

by adafruit_support_bill on Sun Mar 16, 2014 7:00 pm

Bill when you say variable, I am unsure of what you mean.

objta and objt are variables (as far as I can tell). But you haven't showed us enough of your code to know what type of variables they are.

Floating point variables have decimal places. Intgers do not. When you mix them together in calculations, things often get lost in the translation.

adafruit_support_bill
 
Posts: 81533
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

by mjpcarbon on Sun Mar 16, 2014 7:18 pm

understood, I had turned it into an integer thus losing the decimal

mjpcarbon
 
Posts: 435
Joined: Fri Nov 29, 2013 8:57 pm

Please be positive and constructive with your questions and comments.