legionella detector

Dependencies:   mbed

Revision:
2:9d6daa8a091c
diff -r 87661a0c8ba3 -r 9d6daa8a091c TMP102/TMP102.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP102/TMP102.h	Tue Aug 23 09:55:54 2022 +0000
@@ -0,0 +1,73 @@
+// it is good practice to put a comment block on the top, with the name and details of the library
+// you can also include version numbers to keep track of changes/additions
+
+/* TMP102
+
+Simple library to get the temperature data from a TMP102 sensor over I2C.
+
+v 1.0 - initial release
+
+(c) Craig A. Evans, University of Leeds, Jan 2016
+
+*/
+
+// this is called a header guard and prevents a library from being included more than once
+// if it is not already defined, it is defined. If it it already defined, it won't be defined again
+// the header guard is closed at the end of the file
+#ifndef TMP102_H
+#define TMP102_H
+
+// the next thing in a library is usually any required defines
+// addresses for ADD0 connected to GND
+#define TMP102_ADD      0x48
+#define TMP102_R_ADD    0x91
+#define TMP102_W_ADD    0x90
+
+// register addresses
+#define TEMP_REG    0x00
+#define CONFIG_REG  0x01
+#define THIGH_REG   0x02
+#define TLOW_REG    0x03
+
+// we need to include the mbed header (this will also have a header guard to prevent it being included more than once)
+#include "mbed.h"
+
+// a library is actually just a C++ class, we will create an instance of this class (an object) in our main code
+class TMP102
+{
+    // we define the methods that are 'public' i.e. able to be used by the user
+public:
+    
+    // this is a 'constructor' and is used to create the object
+    TMP102(PinName sda, PinName scl);
+    
+    // we will also create an initialisation method
+    void init();
+    
+    // and a method to get the temperature - note the return type
+    float get_temperature();
+    
+    // we also have 'private' methods that can be used in the library itself, but not called directly by the user
+private:
+
+    // called in event of error - flashes LED and hangs 
+    void error();
+    // reads temperature from the sensor
+    void read_temperature();
+    
+
+    // we also do the same for any variables
+public:
+    // don't generally allow direct access to variables, instead use 'accessor' and 'mutator' methods
+    
+private:
+
+    // class data member names often have a trailing underscore to make them easily identifiable
+    I2C* i2c_;
+    DigitalOut* led_;
+    float temperature_;
+
+};
+
+// end of the header guard
+#endif
\ No newline at end of file