Bulme library for LM75B temp. sensor
Revision 0:c622220fe79d, committed 2016-03-14
- Comitter:
- fritzhausmann
- Date:
- Mon Mar 14 13:30:16 2016 +0000
- Commit message:
- Bulme library for LM75B temp. sensor
Changed in this revision
LM75B.cpp | Show annotated file Show diff for this revision Revisions of this file |
LM75B.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.cpp Mon Mar 14 13:30:16 2016 +0000 @@ -0,0 +1,19 @@ +#include "LM75B.h" + +LM75B :: LM75B(PinName sda, PinName scl) : i2c(sda, scl) +{ + cmd[0] = LM75B_CONF; // Pointerregister + cmd[1] = 0x0; // Default siehe 7.4.2 Tabelle 8 + i2c.write(LM75B_ADDR, cmd, 2); // Adr., char *, Länge +} + +float LM75B :: read() +{ + cmd[0] = LM75B_TEMP; + + i2c.write(LM75B_ADDR, cmd, 1); // sende Temperatur Befehl + i2c.read(LM75B_ADDR, cmd, 2); // bekommmen den command string + return (float ((cmd[0] << 8) | cmd[1])/256.0); +} + +LM75B :: ~LM75B() {} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.h Mon Mar 14 13:30:16 2016 +0000 @@ -0,0 +1,23 @@ +#include "mbed.h" +#ifndef LM75B_H +#define LM75B_H + +// LM75B Adresse +#define LM75B_ADDR 0x90 + +// LM75B Register +#define LM75B_CONF 0x01 +#define LM75B_TEMP 0x00 + +class LM75B +{ + public: + LM75B(PinName sda, PinName scl); // I2C Pins übergeben p28, p27 + ~LM75B(); + float read(); + + private: + char cmd[2]; + I2C i2c; +}; +#endif \ No newline at end of file