SHARE
TWEET

Untitled

a guest Jun 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const byte REG_ADDR_RESULT = 0x00;
  2.   const byte REG_ADDR_CONFIG = 0x02;
  3.  
  4.   // initialize the Wire library
  5.   Wire.begin();
  6.   Wire.setClock(400000);
  7.  
  8.   // configure the ADC
  9.   Wire.beginTransmission(I2C_ADC121);
  10.   Wire.write(REG_ADDR_CONFIG);
  11.   Wire.write(REG_ADDR_RESULT);
  12.   Wire.endTransmission();
  13.  
  14.   // set the 'result' register as default
  15.   Wire.beginTransmission(I2C_ADC121);
  16.   Wire.write(REG_ADDR_RESULT);
  17.   Wire.endTransmission();
  18.      
  19. unsigned short adcRead() {
  20.   Wire.requestFrom(I2C_ADC121, 2); // request 2 bytes
  21.   byte buff[2];
  22.   Wire.readBytes(buff, 2); // read2 bytes
  23.   return (buff[0] << 8) | buff[1]; // get the result as 16 bit number
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top