Working Menu, additions to be made

Dependencies:   mbed

Committer:
jackmcgarley
Date:
Wed Aug 24 18:48:25 2022 +0000
Revision:
15:61d9a4e63b99
Working menu, additions to be made;

Who changed what in which revision?

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