|
5 | 5 | * Paul Clark
|
6 | 6 | * SparkFun Electronics
|
7 | 7 | * December 7th 2021
|
8 |
| - * |
| 8 | + * |
9 | 9 | * This is the code we use to test the SPX-18981 Ambient Light Sensor.
|
10 | 10 | * LED_BUILTIN will light up if the VEML7700 is detected correctly and the lux is within bounds.
|
11 |
| - * |
| 11 | + * |
12 | 12 | * Want to support open source hardware? Buy a board from SparkFun!
|
13 | 13 | * <br>SparkX Ambient Light Sensor - VEML7700 (SPX-18981): https://www.sparkfun.com/products/18981
|
14 |
| - * |
| 14 | + * |
15 | 15 | * Please see LICENSE.md for the license information
|
16 |
| - * |
| 16 | + * |
17 | 17 | */
|
18 | 18 |
|
19 | 19 | #include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
20 | 20 |
|
21 |
| -VEML7700 mySensor; // Create a VEML7700 object |
| 21 | +SparkFunVEML7700 mySensor; // Create a VEML7700 object |
22 | 22 |
|
23 | 23 | void setup()
|
24 | 24 | {
|
25 |
| - Serial.begin(115200); |
26 |
| - Serial.println(F("VEML7700 Production Test")); |
| 25 | + Serial.begin(115200); |
| 26 | + Serial.println(F("VEML7700 Production Test")); |
27 | 27 |
|
28 |
| - pinMode(LED_BUILTIN, OUTPUT); |
29 |
| - digitalWrite(LED_BUILTIN, LOW); |
| 28 | + pinMode(LED_BUILTIN, OUTPUT); |
| 29 | + digitalWrite(LED_BUILTIN, LOW); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | void loop()
|
33 | 33 | {
|
34 |
| - delay(250); // Try every 0.25 seconds |
| 34 | + delay(250); // Try every 0.25 seconds |
35 | 35 |
|
36 |
| - Wire.begin(); |
| 36 | + Wire.begin(); |
37 | 37 |
|
38 |
| - Wire.beginTransmission(0x10); // Detect VEML7700 on address 0x10 |
39 |
| - if (Wire.endTransmission() != 0) |
40 |
| - { |
41 |
| - digitalWrite(LED_BUILTIN, LOW); |
42 |
| - Wire.end(); |
43 |
| - Serial.println(F("Error: nothing detected on address 0x10")); |
44 |
| - return; |
45 |
| - } |
46 |
| - |
47 |
| - //Initialize sensor |
48 |
| - if (mySensor.begin() == false) |
49 |
| - { |
50 |
| - digitalWrite(LED_BUILTIN, LOW); |
51 |
| - Wire.end(); |
52 |
| - Serial.println(F("Error: .begin failed")); |
53 |
| - return; |
54 |
| - } |
| 38 | + Wire.beginTransmission(0x10); // Detect VEML7700 on address 0x10 |
| 39 | + if (Wire.endTransmission() != 0) |
| 40 | + { |
| 41 | + digitalWrite(LED_BUILTIN, LOW); |
| 42 | + Wire.end(); |
| 43 | + Serial.println(F("Error: nothing detected on address 0x10")); |
| 44 | + return; |
| 45 | + } |
55 | 46 |
|
56 |
| - delay(250); // Default integration time is 100ms |
| 47 | + // Initialize sensor |
| 48 | + if (mySensor.begin() == false) |
| 49 | + { |
| 50 | + digitalWrite(LED_BUILTIN, LOW); |
| 51 | + Wire.end(); |
| 52 | + Serial.println(F("Error: .begin failed")); |
| 53 | + return; |
| 54 | + } |
57 | 55 |
|
58 |
| - // Now we read the lux from the sensor |
59 |
| - float lux = mySensor.getLux(); // Read the lux |
| 56 | + delay(250); // Default integration time is 100ms |
60 | 57 |
|
61 |
| - // Check the lux is within bounds |
62 |
| - if ((lux < 20.0) || (lux > 100000.0)) |
63 |
| - { |
64 |
| - digitalWrite(LED_BUILTIN, LOW); |
65 |
| - Wire.end(); |
66 |
| - Serial.print(F("Error: invalid lux reading: ")); |
67 |
| - Serial.println(lux, 4); |
68 |
| - return; |
69 |
| - } |
| 58 | + // Now we read the lux from the sensor |
| 59 | + float lux = mySensor.getLux(); // Read the lux |
| 60 | + |
| 61 | + // Check the lux is within bounds |
| 62 | + if ((lux < 20.0) || (lux > 100000.0)) |
| 63 | + { |
| 64 | + digitalWrite(LED_BUILTIN, LOW); |
| 65 | + Wire.end(); |
| 66 | + Serial.print(F("Error: invalid lux reading: ")); |
| 67 | + Serial.println(lux, 4); |
| 68 | + return; |
| 69 | + } |
70 | 70 |
|
71 |
| - // All good! |
72 |
| - Serial.println(F("Test passed!")); |
73 |
| - digitalWrite(LED_BUILTIN, HIGH); |
74 |
| - Wire.end(); |
| 71 | + // All good! |
| 72 | + Serial.println(F("Test passed!")); |
| 73 | + digitalWrite(LED_BUILTIN, HIGH); |
| 74 | + Wire.end(); |
75 | 75 | }
|
0 commit comments