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