Ian Wolf
/
TEMPFINAL
Fork of Temperature_Reading1 by
Diff: main.cpp
- Revision:
- 0:1f9fae46bbe1
- Child:
- 1:1de97b1145f3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 11 16:20:22 2017 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +// Read temperature from LM75BD + +I2C i2c(PB_9 , PB_8 ); + +Serial pc (SERIAL_TX, SERIAL_RX); + +const int addr7bit = 0x48; // 7 bit I2C address +const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90 + +int main() { + pc.baud(250000); + char cmd[2]; + while (1) { + cmd[0] = 0x01; + cmd[1] = 0x00; + i2c.write(addr8bit, cmd, 2); + + wait(0.5); + + cmd[0] = 0x00; + i2c.write(addr8bit, cmd, 1); + i2c.read( addr8bit, cmd, 2); + + float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); + printf("Temp = %.2f\r\n", tmp); + } +} \ No newline at end of file