i2c_registers.ino (1049B)
1 #include <Adafruit_I2CDevice.h> 2 #include <Adafruit_BusIO_Register.h> 3 4 #define I2C_ADDRESS 0x60 5 Adafruit_I2CDevice i2c_dev = Adafruit_I2CDevice(I2C_ADDRESS); 6 7 8 void setup() { 9 while (!Serial) { delay(10); } 10 Serial.begin(115200); 11 Serial.println("I2C device register test"); 12 13 if (!i2c_dev.begin()) { 14 Serial.print("Did not find device at 0x"); 15 Serial.println(i2c_dev.address(), HEX); 16 while (1); 17 } 18 Serial.print("Device found on address 0x"); 19 Serial.println(i2c_dev.address(), HEX); 20 21 Adafruit_BusIO_Register id_reg = Adafruit_BusIO_Register(&i2c_dev, 0x0C, 2, LSBFIRST); 22 uint16_t id; 23 id_reg.read(&id); 24 Serial.print("ID register = 0x"); Serial.println(id, HEX); 25 26 Adafruit_BusIO_Register thresh_reg = Adafruit_BusIO_Register(&i2c_dev, 0x01, 2, LSBFIRST); 27 uint16_t thresh; 28 thresh_reg.read(&thresh); 29 Serial.print("Initial threshold register = 0x"); Serial.println(thresh, HEX); 30 31 thresh_reg.write(~thresh); 32 33 Serial.print("Post threshold register = 0x"); Serial.println(thresh_reg.read(), HEX); 34 } 35 36 void loop() { 37 38 }