MCP3021

Dependents:   Telliskivi2_2014

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MCP3021.h Source File

MCP3021.h

00001 #ifndef MCP3021_H
00002  
00003 #define MCP3021_H
00004  
00005 #include "mbed.h"
00006  
00007 #define    MCP3021_CONVERSE 0x9B //10011011 NOTE IT ENDS IN 1, this is the READ ADDRESS. This is all this device does.
00008                                  //It opens a conversation via this specific READ address
00009  
00010 //Library for the MCP3021 12 BIT ADC.
00011  
00012 class MCP3021
00013 {
00014 public:
00015  
00016   /*
00017   Creates instance
00018   Connect module using I2C port pins sda and scl. The output is referenced to the supply voltage which can be
00019   2.7v to 5.0v. The read will return the correct voltage, if you supply the correct supplyVoltage when instantiating.
00020   */
00021   MCP3021(PinName sda, PinName scl, float supplyVoltage);
00022   
00023   /*
00024   Destroys instance.
00025   */ 
00026   ~MCP3021();
00027   
00028   /*
00029   Reads the analog register of the MCP3021 and converts it to a useable value. (a voltage) 
00030   */
00031   float read();
00032   
00033 private:
00034   
00035   I2C i2c;
00036   float _supplyVoltage;
00037   char _data[2];
00038  
00039 };
00040  
00041 #endif