Mission Accomplished

Dependencies:   TextLCD mbed

Committer:
pstephens18
Date:
Wed Jan 20 01:01:04 2016 +0000
Revision:
0:96cf16c88314
Final Mission Accomplished
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pstephens18 0:96cf16c88314 1 #include "Temperature.h"
pstephens18 0:96cf16c88314 2 extern I2C acc;
pstephens18 0:96cf16c88314 3
pstephens18 0:96cf16c88314 4 const int addr = 0x90;
pstephens18 0:96cf16c88314 5 char config_t[3];
pstephens18 0:96cf16c88314 6 char temp_read[2];
pstephens18 0:96cf16c88314 7 float temp;
pstephens18 0:96cf16c88314 8
pstephens18 0:96cf16c88314 9 float Temperature()
pstephens18 0:96cf16c88314 10 {
pstephens18 0:96cf16c88314 11 config_t[0] = 0x01; // Setting Up Temperature
pstephens18 0:96cf16c88314 12 config_t[1] = 0x60;
pstephens18 0:96cf16c88314 13 config_t[2] = 0xA0;
pstephens18 0:96cf16c88314 14 acc.write(addr,config_t,3);
pstephens18 0:96cf16c88314 15 config_t[0] =0x00;
pstephens18 0:96cf16c88314 16 acc.write(addr,config_t,1);
pstephens18 0:96cf16c88314 17
pstephens18 0:96cf16c88314 18
pstephens18 0:96cf16c88314 19 wait(.5);
pstephens18 0:96cf16c88314 20 acc.read(addr, temp_read,2); // Reading Temperature
pstephens18 0:96cf16c88314 21 temp= 0.0625*(((temp_read[0] << 8) + temp_read[1]) >> 4); // Converting Temperature to Celcius
pstephens18 0:96cf16c88314 22
pstephens18 0:96cf16c88314 23
pstephens18 0:96cf16c88314 24 return temp;
pstephens18 0:96cf16c88314 25 }