Skip to content

Commit b218ca7

Browse files
committed
Comment examples.
1 parent 97ba2ce commit b218ca7

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

examples/Example01_Basic_OneShot/Example01_Basic_OneShot.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
Using the AMS AS7331 Spectral UV Sensor in Command/One Shot (CMD) Mode.
3+
4+
This example shows how operate the AS7331 in the default CMD mode. The start
5+
command is sent, then delays until the conversion time has passed before
6+
reading out the UV values.
7+
8+
By: Alex Brudner
9+
SparkFun Electronics
10+
Date: 2023/11/17
11+
SparkFun code, firmware, and software is released under the MIT License.
12+
Please see LICENSE.md for further details.
13+
14+
Hardware Connections:
15+
IoT RedBoard --> AS7331
16+
QWIIC --> QWIIC
17+
18+
Serial.print it out at 115200 baud to serial monitor.
19+
20+
Feel like supporting our work? Buy a board from SparkFun!
21+
https://www.sparkfun.com/products/23517 - Qwiic 1x1
22+
https://www.sparkfun.com/products/23518 - Qwiic Mini
23+
*/
24+
125
#include "SparkFun_AS7331.h"
226

327
SfeAS7331ArdI2C myUVSensor;
@@ -9,6 +33,7 @@ void setup() {
933
while(!Serial){delay(100);};
1034
Serial.println("UV LED Example.");
1135

36+
// Initialize sensor and run default setup.
1237
if(myUVSensor.begin() == false) {
1338
Serial.println("Sensor failed to begin. Please check your wiring!");
1439
Serial.println("Spinning...");
@@ -17,6 +42,7 @@ void setup() {
1742

1843
Serial.println("Sensor began.");
1944

45+
// Set measurement mode and change device operating mode to measure.
2046
if(myUVSensor.startMeasurement(MEAS_MODE_CMD) == false) {
2147
Serial.println("Sensor did not get set properly.");
2248
Serial.println("Spinning...");
@@ -29,11 +55,14 @@ void setup() {
2955

3056
void loop() {
3157

58+
// Send a start measurement command.
3259
if(SFE_BUS_OK != myUVSensor.setStartStateMode(START_STATE_ENABLED))
3360
Serial.println("Error starting reading!");
3461

62+
// Wait for a bit longer than the conversion time.
3563
delay(2+(1 << myUVSensor.getConfigConversionTime()));
3664

65+
// Read UV values.
3766
if(SFE_BUS_OK != myUVSensor.readAllUV())
3867
Serial.println("Error reading UV.");
3968

examples/Example02_CONT_Mode/Example02_CONT_Mode.ino

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/*
2+
Using the AMS AS7331 Spectral UV Sensor in Continuous (CONT) Mode.
3+
4+
This example shows how operate the AS7331 in CONT mode. The break time
5+
register sets the delay between measurements so that the processor can read
6+
out the results without interfering with the ADC.
7+
8+
By: Alex Brudner
9+
SparkFun Electronics
10+
Date: 2023/11/27
11+
SparkFun code, firmware, and software is released under the MIT License.
12+
Please see LICENSE.md for further details.
13+
14+
Hardware Connections:
15+
IoT RedBoard --> AS7331
16+
QWIIC --> QWIIC
17+
26 --> INT
18+
19+
Serial.print it out at 115200 baud to serial monitor.
20+
21+
Feel like supporting our work? Buy a board from SparkFun!
22+
https://www.sparkfun.com/products/23517 - Qwiic 1x1
23+
https://www.sparkfun.com/products/23518 - Qwiic Mini
24+
*/
25+
126
#include "SparkFun_AS7331.h"
227

328
SfeAS7331ArdI2C myUVSensor;
@@ -49,6 +74,7 @@ void setup() {
4974

5075
void loop() {
5176

77+
// If an interrupt has been generated...
5278
if(newDataReady) {
5379
newDataReady = false;
5480

examples/Example03_SYNS_Mode/Example03_SYNS_Mode.ino

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
Using the AMS AS7331 Spectral UV Sensor in Synchronous Start (SYNS) Mode.
3+
4+
This example shows how operate the AS7331 in SYNS mode. This uses the active
5+
low SYN pin to start the conversion and relies on an interrupt to signal the
6+
end of conversion.
7+
8+
By: Alex Brudner
9+
SparkFun Electronics
10+
Date: 2023/11/27
11+
SparkFun code, firmware, and software is released under the MIT License.
12+
Please see LICENSE.md for further details.
13+
14+
Hardware Connections:
15+
IoT RedBoard --> AS7331
16+
QWIIC --> QWIIC
17+
26 --> INT
18+
27 --> SYN
19+
20+
Serial.print it out at 115200 baud to serial monitor.
21+
22+
Feel like supporting our work? Buy a board from SparkFun!
23+
https://www.sparkfun.com/products/23517 - Qwiic 1x1
24+
https://www.sparkfun.com/products/23518 - Qwiic Mini
25+
*/
26+
127
#include "SparkFun_AS7331.h"
228

329
SfeAS7331ArdI2C myUVSensor;
@@ -38,12 +64,13 @@ void setup() {
3864
while(1);
3965
}
4066

41-
Serial.println("Set mode to synchronous. Starting measurement...");
67+
Serial.println("Set mode to synchronous start (SYNS). Starting measurement...");
4268

43-
// Begin measurement.
69+
// Set device to be ready to measure.
4470
if(SFE_BUS_OK != myUVSensor.setStartStateMode(START_STATE_ENABLED))
4571
Serial.println("Error starting reading!");
4672

73+
// Send start toggle.
4774
digitalWrite(synPin, LOW);
4875
delay(1);
4976
digitalWrite(synPin, HIGH);
@@ -52,12 +79,14 @@ void setup() {
5279

5380
void loop() {
5481

82+
// If an interrupt has been generated...
5583
if(newDataReady) {
5684
newDataReady = false;
5785

5886
if(SFE_BUS_OK != myUVSensor.readAllUV())
5987
Serial.println("Error reading UV.");
6088

89+
// Start next measurement
6190
digitalWrite(synPin, LOW);
6291
delay(1);
6392
digitalWrite(synPin, HIGH);

0 commit comments

Comments
 (0)