Temperature Conversions
Tom P
Posts: 97
How do I implement BASIC STAMP 2 math to convert a number from Celsius to Fehrenheit?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Tom
http://forums.parallax.com/showthread.php?p=646324
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
2) Because the Stamp only does 16-bit integer arithmetic, you have to decide how much precision you want (tenths of a degree or degrees or what?)
3) Have a look at EmeSystems' website (www.emesystems.com) for all kinds of information on doing fixed point arithmetic with the Stamp, particularly the webpage on math. There are lots of practical examples with sample code for the Stamp.
celcius to F
double it and add 32 (ie 20C = 72F)
F to celcius
subtract 32 then halve it (ie 80F = 24C)
2. more generally: c to F
F= (9/5 * C) +32
F to C
C= (F-32)*5/9
As Mike has pointed out, watch your variable sizes and anticipate the maximum possible result of any calculations.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Whit+