Dependencies:   mbed

Fork of Temperature_Reading1 by jack kemnitz

main.cpp

Committer:
212600191
Date:
2017-08-11
Revision:
0:1f9fae46bbe1
Child:
1:1de97b1145f3

File content as of revision 0:1f9fae46bbe1:

#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);
    }
}