|
5 | 5 | * Paul Clark
|
6 | 6 | * SparkFun Electronics
|
7 | 7 | * November 4th 2021
|
8 |
| - * |
| 8 | + * |
9 | 9 | * This example demonstrates how to shut down the VEML7700.
|
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 | unsigned long lastMillis = 0; // Keep track of time
|
23 | 23 |
|
24 |
| -VEML7700_shutdown_t shutdownState = VEML7700_POWER_ON; // Toggle between VEML7700_POWER_ON and VEML7700_SHUT_DOWN |
| 24 | +// start with a power on state |
| 25 | +bool shutdownState = false; |
25 | 26 |
|
26 | 27 | void setup()
|
27 | 28 | {
|
28 |
| - Serial.begin(115200); |
29 |
| - Serial.println(F("SparkFun VEML7700 Example")); |
| 29 | + Serial.begin(115200); |
| 30 | + Serial.println(F("SparkFun VEML7700 Example")); |
30 | 31 |
|
31 |
| - Wire.begin(); |
| 32 | + Wire.begin(); |
32 | 33 |
|
33 |
| - //mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
| 34 | + // mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial |
34 | 35 |
|
35 |
| - // Begin the VEML7700 using the Wire I2C port |
36 |
| - // .begin will return true on success, or false on failure to communicate |
37 |
| - if (mySensor.begin() == false) |
38 |
| - { |
39 |
| - Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing..."); |
40 |
| - while (1) |
41 |
| - ; |
42 |
| - } |
| 36 | + // Begin the VEML7700 using the Wire I2C port |
| 37 | + // .begin will return true on success, or false on failure to communicate |
| 38 | + if (mySensor.begin() == false) |
| 39 | + { |
| 40 | + Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing..."); |
| 41 | + while (1) |
| 42 | + ; |
| 43 | + } |
43 | 44 |
|
44 |
| - lastMillis = millis(); // Keep track of time |
| 45 | + lastMillis = millis(); // Keep track of time |
45 | 46 | }
|
46 | 47 |
|
47 | 48 | void loop()
|
48 | 49 | {
|
49 |
| - if (shutdownState == VEML7700_POWER_ON) // Are we "On"? (Comment this line if you are interested in how it effects the sleep current) |
50 |
| - { |
51 |
| - Serial.print(F("Lux: ")); |
52 |
| - Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it |
53 |
| - } |
54 |
| - |
55 |
| - //Check if it is time to change the power state |
56 |
| - if (millis() > (lastMillis + 5000)) // Change state every 5 seconds |
57 |
| - { |
58 |
| - lastMillis = millis(); // Keep track of time |
59 |
| - |
60 |
| - if (shutdownState == VEML7700_POWER_ON) // Are we "On"? |
| 50 | + // Are we "On"? (Comment this line if you are interested in how it effects the sleep current) |
| 51 | + if (shutdownState == false) |
61 | 52 | {
|
62 |
| - shutdownState = VEML7700_SHUT_DOWN; // Put sensor to sleep |
63 |
| - mySensor.setShutdown(shutdownState); |
64 |
| - |
65 |
| - //mySensor.shutDown(); // This would do the same thing |
| 53 | + Serial.print(F("Lux: ")); |
| 54 | + Serial.println(mySensor.getLux(), 4); // Read the lux from the sensor and print it |
66 | 55 | }
|
67 |
| - else |
| 56 | + |
| 57 | + // Check if it is time to change the power state |
| 58 | + if (millis() > (lastMillis + 5000)) // Change state every 5 seconds |
68 | 59 | {
|
69 |
| - shutdownState = VEML7700_POWER_ON; // Power sensor on |
70 |
| - mySensor.setShutdown(shutdownState); |
71 |
| - |
72 |
| - //mySensor.powerOn(); // This would do the same thing |
| 60 | + lastMillis = millis(); // Keep track of time |
| 61 | + |
| 62 | + shutdownState = !shutdownState; // Toggle the shutdown state |
| 63 | + mySensor.setShutdown(shutdownState); // Set the shutdown state |
| 64 | + |
| 65 | + Serial.print("Power - "); |
| 66 | + Serial.println(shutdownState ? "Off" : "On"); |
73 | 67 | }
|
74 |
| - } |
75 | 68 |
|
76 |
| - delay(125); |
| 69 | + delay(125); |
77 | 70 | }
|
0 commit comments