Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte REG_ADDR_RESULT = 0x00;
- const byte REG_ADDR_CONFIG = 0x02;
- // initialize the Wire library
- Wire.begin();
- Wire.setClock(400000);
- // configure the ADC
- Wire.beginTransmission(I2C_ADC121);
- Wire.write(REG_ADDR_CONFIG);
- Wire.write(REG_ADDR_RESULT);
- Wire.endTransmission();
- // set the 'result' register as default
- Wire.beginTransmission(I2C_ADC121);
- Wire.write(REG_ADDR_RESULT);
- Wire.endTransmission();
- unsigned short adcRead() {
- Wire.requestFrom(I2C_ADC121, 2); // request 2 bytes
- byte buff[2];
- Wire.readBytes(buff, 2); // read2 bytes
- return (buff[0] << 8) | buff[1]; // get the result as 16 bit number
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement