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