A class library development test using TMP102 (I2C temperature sensor).
test_TMP102.h@1:c9c43b132ed7, 2017-11-26 (annotated)
- Committer:
- yasubumi
- Date:
- Sun Nov 26 00:05:12 2017 +0000
- Revision:
- 1:c9c43b132ed7
- Parent:
- 0:89475bc39c8b
- Child:
- 2:494a328aed3e
make two constructors (1. use GPIO pin name, 2. use I2C object)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasubumi | 0:89475bc39c8b | 1 | #include "mbed.h" |
yasubumi | 0:89475bc39c8b | 2 | |
yasubumi | 0:89475bc39c8b | 3 | // TMP102 I2C slave address(ADD0 connected to GND) |
yasubumi | 0:89475bc39c8b | 4 | #define ADDR_TMP102 0x90 |
yasubumi | 0:89475bc39c8b | 5 | |
yasubumi | 0:89475bc39c8b | 6 | // TMP102 registers |
yasubumi | 0:89475bc39c8b | 7 | #define TMP102_Temp 0x00 |
yasubumi | 0:89475bc39c8b | 8 | #define TMP102_Conf 0x01 |
yasubumi | 0:89475bc39c8b | 9 | #define TMP102_Tlow 0x02 |
yasubumi | 0:89475bc39c8b | 10 | #define TMP102_Thigh 0x03 |
yasubumi | 0:89475bc39c8b | 11 | |
yasubumi | 0:89475bc39c8b | 12 | class test_TMP102 |
yasubumi | 0:89475bc39c8b | 13 | { |
yasubumi | 0:89475bc39c8b | 14 | public: |
yasubumi | 1:c9c43b132ed7 | 15 | test_TMP102(PinName sda, PinName scl, char address = ADDR_TMP102); |
yasubumi | 1:c9c43b132ed7 | 16 | test_TMP102(I2C &i2c_obj, char address = ADDR_TMP102); |
yasubumi | 0:89475bc39c8b | 17 | ~test_TMP102(); |
yasubumi | 0:89475bc39c8b | 18 | void init(void); |
yasubumi | 0:89475bc39c8b | 19 | float read(void); |
yasubumi | 1:c9c43b132ed7 | 20 | operator float(void); |
yasubumi | 0:89475bc39c8b | 21 | private: |
yasubumi | 1:c9c43b132ed7 | 22 | I2C *i2c_p; |
yasubumi | 1:c9c43b132ed7 | 23 | I2C &i2c; |
yasubumi | 1:c9c43b132ed7 | 24 | char adr; |
yasubumi | 0:89475bc39c8b | 25 | }; |