Skip to content

Commit 926668e

Browse files
clawpiladyada
andcommitted
Fix interrupt thresholds: low must be above ambient for transitions
Co-authored-by: ladyada <limor@ladyada.net>
1 parent 57d2202 commit 926668e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

examples/interrupt_threshold/interrupt_threshold.ino

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,16 @@ void setup() {
5858
Serial.print(F(" Threshold: "));
5959
Serial.println(threshold);
6060

61-
// Set up proximity interrupt for close detection
62-
vcnl.setProxLowThreshold(0);
61+
// Set up proximity interrupt for close/away detection
62+
// IMPORTANT: Interrupts fire on TRANSITIONS. The sensor must be below
63+
// the low threshold (far state) before it can trigger CLOSE by crossing
64+
// above the high threshold. Set low threshold above ambient so the
65+
// sensor starts in the "far" state.
66+
uint16_t lowThreshold = (ambient + threshold) / 2; // midpoint
67+
vcnl.setProxLowThreshold(lowThreshold);
6368
vcnl.setProxHighThreshold(threshold);
69+
Serial.print(F("Low threshold: "));
70+
Serial.println(lowThreshold);
6471
vcnl.setProxPersistence(VCNL4030_PROX_PERS_1);
6572
vcnl.setProxInterruptMode(VCNL4030_PROX_INT_BOTH);
6673

0 commit comments

Comments
 (0)