Skip to content

Commit b3146a5

Browse files
committed
update for v2.0 of library
1 parent 6919bb5 commit b3146a5

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

examples/Example4_shutDown/Example4_shutDown.ino

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,66 @@
55
* Paul Clark
66
* SparkFun Electronics
77
* November 4th 2021
8-
*
8+
*
99
* This example demonstrates how to shut down the VEML7700.
10-
*
10+
*
1111
* Want to support open source hardware? Buy a board from SparkFun!
1212
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13-
*
13+
*
1414
* Please see LICENSE.md for the license information
15-
*
15+
*
1616
*/
1717

1818
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
1919

20-
VEML7700 mySensor; // Create a VEML7700 object
20+
SparkFunVEML7700 mySensor; // Create a VEML7700 object
2121

2222
unsigned long lastMillis = 0; // Keep track of time
2323

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;
2526

2627
void setup()
2728
{
28-
Serial.begin(115200);
29-
Serial.println(F("SparkFun VEML7700 Example"));
29+
Serial.begin(115200);
30+
Serial.println(F("SparkFun VEML7700 Example"));
3031

31-
Wire.begin();
32+
Wire.begin();
3233

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
3435

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+
}
4344

44-
lastMillis = millis(); // Keep track of time
45+
lastMillis = millis(); // Keep track of time
4546
}
4647

4748
void loop()
4849
{
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)
6152
{
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
6655
}
67-
else
56+
57+
// Check if it is time to change the power state
58+
if (millis() > (lastMillis + 5000)) // Change state every 5 seconds
6859
{
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");
7367
}
74-
}
7568

76-
delay(125);
69+
delay(125);
7770
}

0 commit comments

Comments
 (0)