2323 https://www.sparkfun.com/products/23518 - Qwiic Mini
2424*/
2525
26- #include " SparkFun_AS7331.h"
26+ #include < Arduino.h>
27+ #include < Wire.h>
28+ #include < SparkFun_AS7331.h>
2729
2830SfeAS7331ArdI2C myUVSensor;
2931
30- int8_t result = SFE_BUS_OK;
31-
3232const uint8_t interruptPin = 26 ;
3333volatile bool newDataReady = false ;
3434
@@ -37,28 +37,32 @@ void setup() {
3737 while (!Serial){delay (100 );};
3838 Serial.println (" AS7331 UV A/B/C Continuous mode example." );
3939
40+ Wire.begin ();
41+
4042 // Configure Interrupt.
4143 pinMode (interruptPin, INPUT);
4244 attachInterrupt (digitalPinToInterrupt (interruptPin), dataReadyInterrupt, RISING);
4345
4446 // Initialize sensor and run default setup.
4547 if (myUVSensor.begin () == false ) {
4648 Serial.println (" Sensor failed to begin. Please check your wiring!" );
47- Serial.println (" Spinning ..." );
49+ Serial.println (" Halting ..." );
4850 while (1 );
4951 }
5052
5153 Serial.println (" Sensor began." );
5254
55+ // Set the delay between measurements so that the processor can read out the
56+ // results without interfering with the ADC.
5357 // Set break time to 900us (112 * 8us) to account for the time it takes to poll data.
54- if (SFE_BUS_OK != myUVSensor.setBreakTime (112 )) {
58+ if (kSTkErrOk != myUVSensor.setBreakTime (112 )) {
5559 Serial.println (" Sensor did not set break time properly." );
56- Serial.println (" Spinning ..." );
60+ Serial.println (" Halting ..." );
5761 while (1 );
5862 }
5963
6064 // Set measurement mode and change device operating mode to measure.
61- if (myUVSensor.startMeasurement (MEAS_MODE_CONT) == false ) {
65+ if (myUVSensor.prepareMeasurement (MEAS_MODE_CONT) == false ) {
6266 Serial.println (" Sensor did not get set properly." );
6367 Serial.println (" Spinning..." );
6468 while (1 );
@@ -67,7 +71,7 @@ void setup() {
6771 Serial.println (" Set mode to continuous. Starting measurement..." );
6872
6973 // Begin measurement.
70- if (SFE_BUS_OK != myUVSensor.setStartStateMode (START_STATE_ENABLED ))
74+ if (kSTkErrOk != myUVSensor.setStartState ( true ))
7175 Serial.println (" Error starting reading!" );
7276
7377}
@@ -78,15 +82,15 @@ void loop() {
7882 if (newDataReady) {
7983 newDataReady = false ;
8084
81- if (SFE_BUS_OK != myUVSensor.readAllUV ())
85+ if (kSTkErrOk != myUVSensor.readAllUV ())
8286 Serial.println (" Error reading UV." );
8387
8488 Serial.print (" UVA:" );
85- Serial.print (myUVSensor.measures . uva );
89+ Serial.print (myUVSensor.getUVA () );
8690 Serial.print (" UVB:" );
87- Serial.print (myUVSensor.measures . uvb );
91+ Serial.print (myUVSensor.getUVB () );
8892 Serial.print (" UVC:" );
89- Serial.println (myUVSensor.measures . uvc );
93+ Serial.println (myUVSensor.getUVC () );
9094 }
9195
9296}
0 commit comments