|
5 | 5 | * Paul Clark
|
6 | 6 | * SparkFun Electronics
|
7 | 7 | * November 4th 2021
|
8 |
| - * |
| 8 | + * |
9 | 9 | * This example demonstrates how to change the VEML7700's threshold settings.
|
10 |
| - * |
| 10 | + * |
11 | 11 | * Want to support open source hardware? Buy a board from SparkFun!
|
12 | 12 | * <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
|
13 |
| - * |
| 13 | + * |
14 | 14 | * Please see LICENSE.md for the license information
|
15 |
| - * |
| 15 | + * |
16 | 16 | */
|
17 | 17 |
|
18 | 18 | #include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
|
19 | 19 |
|
20 |
| -VEML7700 mySensor; // Create a VEML7700 object |
| 20 | +SparkFunVEML7700 mySensor; // Create a VEML7700 object |
21 | 21 |
|
22 | 22 | void setup()
|
23 | 23 | {
|
24 |
| - Serial.begin(115200); |
25 |
| - Serial.println(F("SparkFun VEML7700 Example")); |
26 |
| - |
27 |
| - Wire.begin(); |
28 |
| - |
29 |
| - //mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
30 |
| - |
31 |
| - // Begin the VEML7700 using the Wire I2C port |
32 |
| - // .begin will return true on success, or false on failure to communicate |
33 |
| - if (mySensor.begin() == false) |
34 |
| - { |
35 |
| - Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing..."); |
36 |
| - while (1) |
37 |
| - ; |
38 |
| - } |
39 |
| - |
40 |
| - //Let's change the high threshold to 30000 counts: |
41 |
| - mySensor.setHighThreshold(30000); |
42 |
| - |
43 |
| - //Confirm the high threshold was set correctly |
44 |
| - Serial.print(F("The high threshold is: ")); |
45 |
| - Serial.println(mySensor.getHighThreshold()); |
46 |
| - |
47 |
| - //Let's change the low threshold to 1000 counts: |
48 |
| - mySensor.setLowThreshold(1000); |
49 |
| - |
50 |
| - //Confirm the low threshold was set correctly |
51 |
| - Serial.print(F("The low threshold is: ")); |
52 |
| - Serial.println(mySensor.getLowThreshold()); |
53 |
| - |
54 |
| - //Enable the high and low threshold interrupts |
55 |
| - mySensor.setInterruptEnable(VEML7700_INT_ENABLE); |
56 |
| - |
57 |
| - //Check that the interrupts are enabled |
58 |
| - Serial.print(F("Interrupts are ")); |
59 |
| - VEML7700_interrupt_enable_t ie; |
60 |
| - mySensor.getInterruptEnable(&ie); |
61 |
| - if ((ie == VEML7700_INT_DISABLE) || ( ie == VEML7700_INT_INVALID)) |
62 |
| - Serial.print(F("not ")); |
63 |
| - Serial.println(F("enabled")); |
| 24 | + Serial.begin(115200); |
| 25 | + Serial.println(F("SparkFun VEML7700 Example")); |
| 26 | + |
| 27 | + Wire.begin(); |
| 28 | + |
| 29 | + // mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 30 | + |
| 31 | + // Begin the VEML7700 using the Wire I2C port |
| 32 | + // .begin will return true on success, or false on failure to communicate |
| 33 | + if (mySensor.begin() == false) |
| 34 | + { |
| 35 | + Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing..."); |
| 36 | + while (1) |
| 37 | + ; |
| 38 | + } |
| 39 | + |
| 40 | + // Let's change the high threshold to 30000 counts: |
| 41 | + mySensor.setHighThreshold(30000); |
| 42 | + |
| 43 | + // Confirm the high threshold was set correctly |
| 44 | + Serial.print(F("The high threshold is: ")); |
| 45 | + Serial.println(mySensor.highThreshold()); |
| 46 | + |
| 47 | + // Let's change the low threshold to 1000 counts: |
| 48 | + mySensor.setLowThreshold(1000); |
| 49 | + |
| 50 | + // Confirm the low threshold was set correctly |
| 51 | + Serial.print(F("The low threshold is: ")); |
| 52 | + Serial.println(mySensor.lowThreshold()); |
| 53 | + |
| 54 | + // Enable the high and low threshold interrupts |
| 55 | + mySensor.enableInterrupt(true); |
| 56 | + |
| 57 | + // Check that the interrupts are enabled |
| 58 | + Serial.print(F("Interrupts are ")); |
| 59 | + |
| 60 | + if (mySensor.isInterruptEnabled() == false) |
| 61 | + Serial.print(F("not ")); |
| 62 | + Serial.println(F("enabled")); |
64 | 63 | }
|
65 | 64 |
|
66 | 65 | void loop()
|
67 | 66 | {
|
68 |
| - Serial.print(F("Ambient: ")); |
69 |
| - Serial.print(mySensor.getAmbientLight()); // Read the ambient light level from the sensor and print it |
70 |
| - |
71 |
| - // Note: reading the interrupt status register clears the interrupts, so we need to check both |
72 |
| - // the high and low interrupt flags in a single read |
73 |
| - |
74 |
| - VEML7700_interrupt_status_t intStatus = mySensor.getInterruptStatus(); // Check the interrupt status |
75 |
| - |
76 |
| - // Possible values for intStatus are: |
77 |
| - // VEML7700_INT_STATUS_NONE |
78 |
| - // VEML7700_INT_STATUS_HIGH |
79 |
| - // VEML7700_INT_STATUS_LOW |
80 |
| - // VEML7700_INT_STATUS_BOTH |
81 |
| - // VEML7700_INT_STATUS_INVALID |
82 |
| - |
83 |
| - if (intStatus == VEML7700_INT_STATUS_INVALID) |
84 |
| - { |
85 |
| - Serial.print(F("\tInterrupt Status Read Error!")); |
86 |
| - } |
87 |
| - else |
88 |
| - { |
89 |
| - if (intStatus & VEML7700_INT_STATUS_HIGH) // Use a logical AND to check if the high flag is set |
90 |
| - Serial.print(F("\tHigh Threshold Exceeded")); |
91 |
| - |
92 |
| - if (intStatus & VEML7700_INT_STATUS_LOW) // Use a logical AND to check if the low flag is set |
93 |
| - Serial.print(F("\tLow Threshold Exceeded")); |
94 |
| - } |
95 |
| - |
96 |
| - Serial.println(); |
97 |
| - |
98 |
| - delay(250); |
| 67 | + Serial.print(F("Ambient: ")); |
| 68 | + Serial.print(mySensor.getAmbientLight()); // Read the ambient light level from the sensor and print it |
| 69 | + |
| 70 | + // Note: reading the interrupt status register clears the interrupts, so we need to check both |
| 71 | + // the high and low interrupt flags in a single read |
| 72 | + |
| 73 | + VEML7700_interrupt_status_t intStatus = mySensor.interruptStatus(); // Check the interrupt status |
| 74 | + |
| 75 | + // Possible values for intStatus are: |
| 76 | + // VEML7700_INT_STATUS_NONE |
| 77 | + // VEML7700_INT_STATUS_HIGH |
| 78 | + // VEML7700_INT_STATUS_LOW |
| 79 | + // VEML7700_INT_STATUS_BOTH |
| 80 | + // VEML7700_INT_STATUS_INVALID |
| 81 | + |
| 82 | + if (intStatus == VEML7700_INT_STATUS_INVALID) |
| 83 | + { |
| 84 | + Serial.print(F("\tInterrupt Status Read Error!")); |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + if (intStatus & VEML7700_INT_STATUS_HIGH) // Use a logical AND to check if the high flag is set |
| 89 | + Serial.print(F("\tHigh Threshold Exceeded")); |
| 90 | + |
| 91 | + if (intStatus & VEML7700_INT_STATUS_LOW) // Use a logical AND to check if the low flag is set |
| 92 | + Serial.print(F("\tLow Threshold Exceeded")); |
| 93 | + } |
| 94 | + |
| 95 | + Serial.println(); |
| 96 | + |
| 97 | + delay(250); |
99 | 98 | }
|
0 commit comments