Used & amended by D.Leaming, University of Lincoln, December 2021

Dependents:   Final_Project_V05_DLeaming_25574043_copy Final_Project_V06_DLeaming_25574043 Final_Project_V07_DLeaming_25574043 Final_Project_V08_DLeaming_25574043 ... more

Committer:
legstar85
Date:
Sun Jan 16 22:45:17 2022 +0000
Revision:
3:1318dd22d0d7
Parent:
2:d95a4e13f6cf
Update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
legstar85 3:1318dd22d0d7 1 /* *
legstar85 2:d95a4e13f6cf 2 * Acknowledgements
legstar85 2:d95a4e13f6cf 3 * Craig A. Evans, University of Leeds, TMP102 Library ,Feb 2016
legstar85 2:d95a4e13f6cf 4 * Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries
legstar85 2:d95a4e13f6cf 5 *
legstar85 2:d95a4e13f6cf 6 */
legstar85 2:d95a4e13f6cf 7
eencae 0:8818842a3573 8 // it is good practice to put a comment block on the top, with the name and details of the library
eencae 0:8818842a3573 9 // you can also include version numbers to keep track of changes/additions
eencae 0:8818842a3573 10
eencae 0:8818842a3573 11 /* TMP102
eencae 0:8818842a3573 12
eencae 0:8818842a3573 13 Simple library to get the temperature data from a TMP102 sensor over I2C.
eencae 0:8818842a3573 14
eencae 0:8818842a3573 15 v 1.0 - initial release
eencae 0:8818842a3573 16
eencae 0:8818842a3573 17 (c) Craig A. Evans, University of Leeds, Jan 2016
eencae 0:8818842a3573 18
eencae 0:8818842a3573 19 */
eencae 0:8818842a3573 20
eencae 0:8818842a3573 21 // this is called a header guard and prevents a library from being included more than once
eencae 0:8818842a3573 22 // if it is not already defined, it is defined. If it it already defined, it won't be defined again
eencae 0:8818842a3573 23 // the header guard is closed at the end of the file
eencae 0:8818842a3573 24 #ifndef TMP102_H
eencae 0:8818842a3573 25 #define TMP102_H
eencae 0:8818842a3573 26
eencae 0:8818842a3573 27 // the next thing in a library is usually any required defines
eencae 0:8818842a3573 28 // addresses for ADD0 connected to GND
eencae 0:8818842a3573 29 #define TMP102_ADD 0x48
eencae 0:8818842a3573 30 #define TMP102_R_ADD 0x91
eencae 0:8818842a3573 31 #define TMP102_W_ADD 0x90
eencae 0:8818842a3573 32
eencae 0:8818842a3573 33 // register addresses
eencae 0:8818842a3573 34 #define TEMP_REG 0x00
eencae 0:8818842a3573 35 #define CONFIG_REG 0x01
eencae 0:8818842a3573 36 #define THIGH_REG 0x02
eencae 0:8818842a3573 37 #define TLOW_REG 0x03
eencae 0:8818842a3573 38
eencae 0:8818842a3573 39 // we need to include the mbed header (this will also have a header guard to prevent it being included more than once)
eencae 0:8818842a3573 40 #include "mbed.h"
eencae 0:8818842a3573 41
eencae 0:8818842a3573 42 // a library is actually just a C++ class, we will create an instance of this class (an object) in our main code
eencae 0:8818842a3573 43 class TMP102
eencae 0:8818842a3573 44 {
eencae 0:8818842a3573 45 // we define the methods that are 'public' i.e. able to be used by the user
eencae 0:8818842a3573 46 public:
eencae 0:8818842a3573 47
eencae 0:8818842a3573 48 // this is a 'constructor' and is used to create the object
eencae 0:8818842a3573 49 TMP102(PinName sda, PinName scl);
eencae 0:8818842a3573 50
eencae 0:8818842a3573 51 // we will also create an initialisation method
eencae 0:8818842a3573 52 void init();
eencae 0:8818842a3573 53
eencae 0:8818842a3573 54 // and a method to get the temperature - note the return type
eencae 0:8818842a3573 55 float get_temperature();
eencae 0:8818842a3573 56
eencae 0:8818842a3573 57 // we also have 'private' methods that can be used in the library itself, but not called directly by the user
eencae 0:8818842a3573 58 private:
eencae 0:8818842a3573 59
eencae 0:8818842a3573 60 // called in event of error - flashes LED and hangs
eencae 0:8818842a3573 61 void error();
eencae 0:8818842a3573 62 // reads temperature from the sensor
eencae 0:8818842a3573 63 void read_temperature();
eencae 0:8818842a3573 64
eencae 0:8818842a3573 65
eencae 0:8818842a3573 66 // we also do the same for any variables
eencae 0:8818842a3573 67 public:
eencae 0:8818842a3573 68 // don't generally allow direct access to variables, instead use 'accessor' and 'mutator' methods
eencae 0:8818842a3573 69
eencae 0:8818842a3573 70 private:
eencae 0:8818842a3573 71
eencae 0:8818842a3573 72 // class data member names often have a trailing underscore to make them easily identifiable
eencae 0:8818842a3573 73 I2C* i2c_;
eencae 0:8818842a3573 74 DigitalOut* led_;
eencae 0:8818842a3573 75 float temperature_;
eencae 0:8818842a3573 76
eencae 0:8818842a3573 77 };
eencae 0:8818842a3573 78
eencae 0:8818842a3573 79 // end of the header guard
eencae 0:8818842a3573 80 #endif