(DA) Internet of Things and Smart Electronics- ELE3006M2122 / Mbed 2 deprecated Final_Project_V15_DLeaming_25574043

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TMP102.h Source File

TMP102.h

00001 /* * 
00002 * Prints a string of characters to the screen buffer, string is cut off after the 83rd  pixel.
00003 * @param x - the column number (0 to 83)
00004 * @param y - the row number (0-5) - the display is split into 6 banks - each bank can be considered a row
00005 * @author - David Leaming - 25574043
00006 * @ Date - December 2021
00007 *
00008 * Acknowledgements 
00009 * Craig A. Evans, University of Leeds, TMP102 Library ,Feb 2016
00010 * Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries
00011 *
00012 */ 
00013 
00014 // it is good practice to put a comment block on the top, with the name and details of the library
00015 // you can also include version numbers to keep track of changes/additions
00016 
00017 /* TMP102
00018 
00019 Simple library to get the temperature data from a TMP102 sensor over I2C.
00020 
00021 v 1.0 - initial release
00022 
00023 (c) Craig A. Evans, University of Leeds, Jan 2016
00024 
00025 */
00026 
00027 // this is called a header guard and prevents a library from being included more than once
00028 // if it is not already defined, it is defined. If it it already defined, it won't be defined again
00029 // the header guard is closed at the end of the file
00030 #ifndef TMP102_H
00031 #define TMP102_H
00032 
00033 // the next thing in a library is usually any required defines
00034 // addresses for ADD0 connected to GND
00035 #define TMP102_ADD      0x48
00036 #define TMP102_R_ADD    0x91
00037 #define TMP102_W_ADD    0x90
00038 
00039 // register addresses
00040 #define TEMP_REG    0x00
00041 #define CONFIG_REG  0x01
00042 #define THIGH_REG   0x02
00043 #define TLOW_REG    0x03
00044 
00045 // we need to include the mbed header (this will also have a header guard to prevent it being included more than once)
00046 #include "mbed.h"
00047 
00048 // a library is actually just a C++ class, we will create an instance of this class (an object) in our main code
00049 class TMP102
00050 {
00051     // we define the methods that are 'public' i.e. able to be used by the user
00052 public:
00053     
00054     // this is a 'constructor' and is used to create the object
00055     TMP102(PinName sda, PinName scl);
00056     
00057     // we will also create an initialisation method
00058     void init();
00059     
00060     // and a method to get the temperature - note the return type
00061     float get_temperature();
00062     
00063     // we also have 'private' methods that can be used in the library itself, but not called directly by the user
00064 private:
00065 
00066     // called in event of error - flashes LED and hangs 
00067     void error();
00068     // reads temperature from the sensor
00069     void read_temperature();
00070     
00071 
00072     // we also do the same for any variables
00073 public:
00074     // don't generally allow direct access to variables, instead use 'accessor' and 'mutator' methods
00075     
00076 private:
00077 
00078     // class data member names often have a trailing underscore to make them easily identifiable
00079     I2C* i2c_;
00080     DigitalOut* led_;
00081     float temperature_;
00082 
00083 };
00084 
00085 // end of the header guard
00086 #endif