Skip to content

Commit 6919bb5

Browse files
committed
upgrade the threshold example; add additional backward compat support
1 parent bf140b8 commit 6919bb5

File tree

2 files changed

+86
-76
lines changed

2 files changed

+86
-76
lines changed

examples/Example3_threshold/Example3_threshold.ino

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,94 @@
55
* Paul Clark
66
* SparkFun Electronics
77
* November 4th 2021
8-
*
8+
*
99
* This example demonstrates how to change the VEML7700's threshold settings.
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
void setup()
2323
{
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"));
6463
}
6564

6665
void loop()
6766
{
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);
9998
}

src/sfTk/sfDevVEML7700.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,17 @@ class sfDevVEML7700
536536
*/
537537
VEML7700_interrupt_status_t interruptStatus(void);
538538

539+
/**
540+
* @brief Gets the interrupt status of the VEML7700 sensor.
541+
*
542+
* @deprecated since version 2.0.0, use interruptStatus() instead.
543+
* @return VEML7700_interrupt_status_t The current interrupt status of the sensor.
544+
*/
545+
VEML7700_interrupt_status_t getInterruptStatus(void)
546+
{
547+
return interruptStatus();
548+
} // Get the Interrupt Status object - this is for backward compatibility
549+
539550
private:
540551
/** Provide bit field access to the configuration register */
541552
typedef struct

0 commit comments

Comments
 (0)