simplifying a formula

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

simplifying a formula

Post by mjpcarbon »

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;

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

Post by adafruit_support_bill »

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

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: simplifying a formula

Post by adafruit_support_mike »

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

objta = ( objt * 1.8 ) + 32;
Serial.print( objta );

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

Post by mjpcarbon »

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)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

Post by adafruit_support_bill »

What are the data types of the variables involved?

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

Post by mjpcarbon »

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

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

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: simplifying a formula

Post by adafruit_support_bill »

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.

User avatar
mjpcarbon
 
Posts: 436
Joined: Fri Nov 29, 2013 8:57 pm

Re: simplifying a formula

Post by mjpcarbon »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”