![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Final
Temperature.cpp@0:5fd3f73db34f, 2016-01-20 (annotated)
- Committer:
- pstephens18
- Date:
- Wed Jan 20 02:15:26 2016 +0000
- Revision:
- 0:5fd3f73db34f
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pstephens18 | 0:5fd3f73db34f | 1 | #include "Temperature.h" |
pstephens18 | 0:5fd3f73db34f | 2 | extern I2C acc; |
pstephens18 | 0:5fd3f73db34f | 3 | |
pstephens18 | 0:5fd3f73db34f | 4 | const int addr = 0x90; |
pstephens18 | 0:5fd3f73db34f | 5 | char config_t[3]; |
pstephens18 | 0:5fd3f73db34f | 6 | char temp_read[2]; |
pstephens18 | 0:5fd3f73db34f | 7 | float temp; |
pstephens18 | 0:5fd3f73db34f | 8 | |
pstephens18 | 0:5fd3f73db34f | 9 | float Temperature() |
pstephens18 | 0:5fd3f73db34f | 10 | { |
pstephens18 | 0:5fd3f73db34f | 11 | config_t[0] = 0x01; // Setting Up Temperature |
pstephens18 | 0:5fd3f73db34f | 12 | config_t[1] = 0x60; |
pstephens18 | 0:5fd3f73db34f | 13 | config_t[2] = 0xA0; |
pstephens18 | 0:5fd3f73db34f | 14 | acc.write(addr,config_t,3); |
pstephens18 | 0:5fd3f73db34f | 15 | config_t[0] =0x00; |
pstephens18 | 0:5fd3f73db34f | 16 | acc.write(addr,config_t,1); |
pstephens18 | 0:5fd3f73db34f | 17 | |
pstephens18 | 0:5fd3f73db34f | 18 | |
pstephens18 | 0:5fd3f73db34f | 19 | wait(.5); |
pstephens18 | 0:5fd3f73db34f | 20 | acc.read(addr, temp_read,2); // Reading Temperature |
pstephens18 | 0:5fd3f73db34f | 21 | temp= 0.0625*(((temp_read[0] << 8) + temp_read[1]) >> 4); // Converting Temperature to Celcius |
pstephens18 | 0:5fd3f73db34f | 22 | |
pstephens18 | 0:5fd3f73db34f | 23 | |
pstephens18 | 0:5fd3f73db34f | 24 | return temp; |
pstephens18 | 0:5fd3f73db34f | 25 | } |