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:
Fri Dec 17 08:26:48 2021 +0000
Revision:
2:d95a4e13f6cf
Parent:
0:8818842a3573
Child:
3:1318dd22d0d7
Used & amended by D.Leaming, University of Lincoln, December 2021

Who changed what in which revision?

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