Jason Schilling / Mbed 2 deprecated miniProject7

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Temperature.cpp Source File

Temperature.cpp

00001 #include "Temperature.h"
00002 I2C i2cTemp(p9, p10);
00003 volatile short rawTemp;
00004     
00005 float tempFar(float temp) { // converts temperature to farenheit
00006     float far;
00007     far = (((0.0625 * rawTemp)*(9/5))+32);
00008     return far;
00009 }
00010 
00011 float tempRan(float temp) { // converts temperature to rankine
00012     float ran;
00013     ran = (((0.0625 * rawTemp)*(9/5))+491.67);
00014     return ran;
00015 }
00016 
00017 float tempKel(float temp){ // cocnverts temperature to kelvin
00018     float kel;
00019     kel = ((0.0625 * rawTemp)+273);
00020     return kel;
00021 }
00022 
00023 void tempConfig(void) { // configures the correct settings for the temperature sensor when the program starts
00024     char buff[3];
00025     const int tempAddr = 0x90;
00026     buff[0] = 0x01;
00027     buff[1] = 0x60;
00028     buff[2] = 0xA0;
00029     i2cTemp.write(tempAddr, buff, 3);
00030     buff[0] = 0x00;
00031     i2cTemp.write(tempAddr, buff, 1);    
00032 }
00033 
00034 float readTemp() { // converts rawTemp (the raw data from the temperature sensor) to degrees celsius
00035     float temp;
00036     char buff[2];
00037     const int tempAddr = 0x90;
00038     i2cTemp.read(tempAddr, buff, 2);
00039     rawTemp = (buff[0] <<8) + buff[1];
00040     rawTemp = rawTemp >> 4;
00041     temp = 0.0625 * rawTemp;
00042     return temp;
00043 }