An application for school
LM75B.cpp@2:80ee8d96656a, 2020-11-05 (annotated)
- Committer:
- deboerengamer
- Date:
- Thu Nov 05 13:35:50 2020 +0000
- Revision:
- 2:80ee8d96656a
- Parent:
- 1:6a70c9303bbe
Made a repository
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:1be38995591b | 1 | #include "LM75B.h" |
chris | 0:1be38995591b | 2 | |
chris | 0:1be38995591b | 3 | LM75B::LM75B(PinName sda, PinName scl) : i2c(sda, scl) |
chris | 0:1be38995591b | 4 | { |
chris | 0:1be38995591b | 5 | char cmd[2]; |
chris | 0:1be38995591b | 6 | cmd[0] = LM75B_Conf; |
chris | 0:1be38995591b | 7 | cmd[1] = 0x0; |
chris | 0:1be38995591b | 8 | i2c.write( LM75B_ADDR, cmd, 2); |
chris | 0:1be38995591b | 9 | } |
chris | 0:1be38995591b | 10 | |
chris | 0:1be38995591b | 11 | |
chris | 0:1be38995591b | 12 | |
chris | 0:1be38995591b | 13 | LM75B::~LM75B() |
chris | 0:1be38995591b | 14 | { |
chris | 0:1be38995591b | 15 | |
chris | 0:1be38995591b | 16 | } |
chris | 0:1be38995591b | 17 | |
deboerengamer | 2:80ee8d96656a | 18 | uint16_t LM75B::read() |
chris | 0:1be38995591b | 19 | { |
chris | 0:1be38995591b | 20 | char cmd[2]; |
chris | 0:1be38995591b | 21 | cmd[0] = LM75B_Temp; |
chris | 0:1be38995591b | 22 | |
chris | 0:1be38995591b | 23 | i2c.write( LM75B_ADDR, cmd, 1); // Send command string |
chris | 0:1be38995591b | 24 | i2c.read( LM75B_ADDR, cmd, 2); // Send command string |
deboerengamer | 2:80ee8d96656a | 25 | return ( uint16_t((cmd[0]<<8)|cmd[1]) ); |
chris | 0:1be38995591b | 26 | } |