1- #include < Adafruit_I2CDevice.h>
21#include < Adafruit_BusIO_Register.h>
2+ #include < Adafruit_I2CDevice.h>
33
44#define AS7331_ADDR 0x74
55
66Adafruit_I2CDevice *i2c_dev;
77
88void setup () {
99 Serial.begin (115200 );
10- while (!Serial) delay (10 );
11-
10+ while (!Serial)
11+ delay (10 );
12+
1213 Serial.println (" BusIO Test for AS7331" );
1314 Serial.println (" =====================" );
14-
15+
1516 i2c_dev = new Adafruit_I2CDevice (AS7331_ADDR );
1617 if (!i2c_dev->begin ()) {
1718 Serial.println (" I2C device not found!" );
18- while (1 );
19+ while (1 )
20+ ;
1921 }
2022 Serial.println (" I2C device found." );
21-
23+
2224 // Method 1: Direct read with buffer
2325 Serial.println (" \n Method 1: Direct i2c_dev->write_then_read()" );
2426 uint8_t reg = 0x02 ;
@@ -29,7 +31,7 @@ void setup() {
2931 } else {
3032 Serial.println (" write_then_read FAILED" );
3133 }
32-
34+
3335 // Method 2: BusIO_Register with explicit 1-byte width
3436 Serial.println (" \n Method 2: BusIO_Register (8-bit, width=1)" );
3537 Adafruit_BusIO_Register agen8 (i2c_dev, 0x02 , 1 );
@@ -40,7 +42,7 @@ void setup() {
4042 } else {
4143 Serial.println (" BusIO_Register read FAILED" );
4244 }
43-
45+
4446 // Method 3: BusIO_Register default (might be 2 bytes?)
4547 Serial.println (" \n Method 3: BusIO_Register (default constructor)" );
4648 Adafruit_BusIO_Register agen_def (i2c_dev, 0x02 );
@@ -51,8 +53,8 @@ void setup() {
5153 } else {
5254 Serial.println (" BusIO_Register default read FAILED" );
5355 }
54-
55- // Method 4: Read as 16-bit
56+
57+ // Method 4: Read as 16-bit
5658 Serial.println (" \n Method 4: BusIO_Register (16-bit)" );
5759 Adafruit_BusIO_Register agen16 (i2c_dev, 0x02 , 2 , LSBFIRST );
5860 uint16_t val16 = 0 ;
@@ -62,10 +64,8 @@ void setup() {
6264 } else {
6365 Serial.println (" 16-bit read FAILED" );
6466 }
65-
67+
6668 Serial.println (" \n Done." );
6769}
6870
69- void loop () {
70- delay (1000 );
71- }
71+ void loop () { delay (1000 ); }
0 commit comments