edge
/
EdgeTeamTest
testje
Diff: main.cpp
- Revision:
- 0:0a5a8dae0fa1
- Child:
- 1:7baef237c57c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 12 13:57:44 2016 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +// Read temperature from TH06 + +// p6 PA_8 / XBEE_PWM0 / XBEE_RSSI / I2C_SCL D15 +// p7 PC_9 / XBEE_PWM1 / I2C_SDA D14 +I2C i2c(PC_9,PA_8); + +const int addr = 0x80; + +int main() { + char cmd[2]; + + while (1) { + cmd[0] = 0xf3; + i2c.write(addr, cmd, 1); + + wait(0.5); + + i2c.read(addr, cmd, 2); + + float temp_code = (cmd[0]<<8)|cmd[1]; + float temp = 175.72*temp_code/65535.0-46.85; + + printf("Temp = %.2f\r\n", temp); + } +} \ No newline at end of file