MCP3021

Dependents:   Telliskivi2_2014

Revision:
0:423652b49d07
diff -r 000000000000 -r 423652b49d07 MCP3021.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP3021.h	Tue Sep 02 15:34:15 2014 +0000
@@ -0,0 +1,41 @@
+#ifndef MCP3021_H
+ 
+#define MCP3021_H
+ 
+#include "mbed.h"
+ 
+#define    MCP3021_CONVERSE 0x9B //10011011 NOTE IT ENDS IN 1, this is the READ ADDRESS. This is all this device does.
+                                 //It opens a conversation via this specific READ address
+ 
+//Library for the MCP3021 12 BIT ADC.
+ 
+class MCP3021
+{
+public:
+ 
+  /*
+  Creates instance
+  Connect module using I2C port pins sda and scl. The output is referenced to the supply voltage which can be
+  2.7v to 5.0v. The read will return the correct voltage, if you supply the correct supplyVoltage when instantiating.
+  */
+  MCP3021(PinName sda, PinName scl, float supplyVoltage);
+  
+  /*
+  Destroys instance.
+  */ 
+  ~MCP3021();
+  
+  /*
+  Reads the analog register of the MCP3021 and converts it to a useable value. (a voltage) 
+  */
+  float read();
+  
+private:
+  
+  I2C i2c;
+  float _supplyVoltage;
+  char _data[2];
+ 
+};
+ 
+#endif
\ No newline at end of file