|
| 1 | +/*! |
| 2 | + * @file Example6_ProductionTest.ino |
| 3 | + * |
| 4 | + * This example was written by: |
| 5 | + * Paul Clark |
| 6 | + * SparkFun Electronics |
| 7 | + * December 7th 2021 |
| 8 | + * |
| 9 | + * This is the code we use to test the SPX-18981 Ambient Light Sensor. |
| 10 | + * LED_BUILTIN will light up if the VEML7700 is detected correctly and the lux is within bounds. |
| 11 | + * |
| 12 | + * Want to support open source hardware? Buy a board from SparkFun! |
| 13 | + * <br>SparkX Ambient Light Sensor - VEML7700 (SPX-18981): https://www.sparkfun.com/products/18981 |
| 14 | + * |
| 15 | + * Please see LICENSE.md for the license information |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700 |
| 20 | + |
| 21 | +VEML7700 mySensor; // Create a VEML7700 object |
| 22 | + |
| 23 | +void setup() |
| 24 | +{ |
| 25 | + Serial.begin(115200); |
| 26 | + Serial.println(F("VEML7700 Production Test")); |
| 27 | + |
| 28 | + pinMode(LED_BUILTIN, OUTPUT); |
| 29 | + digitalWrite(LED_BUILTIN, LOW); |
| 30 | +} |
| 31 | + |
| 32 | +void loop() |
| 33 | +{ |
| 34 | + delay(250); // Try every 0.25 seconds |
| 35 | + |
| 36 | + Wire.begin(); |
| 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 | + } |
| 55 | + |
| 56 | + delay(250); // Default integration time is 100ms |
| 57 | + |
| 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 < 100.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 | + |
| 71 | + // All good! |
| 72 | + Serial.println(F("Test passed!")); |
| 73 | + digitalWrite(LED_BUILTIN, HIGH); |
| 74 | + Wire.end(); |
| 75 | +} |
0 commit comments