Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement