-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathInterruptLight.ino
70 lines (51 loc) · 1.67 KB
/
InterruptLight.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
APDS9960 - Light/Color Sensor, Interrupt
This example reads the light (C) and color (RGB) data from the on-board APDS9960
sensor of the Nano 33 BLE Sense and prints the proximity value to the Serial Monitor.
If the measure is outside the interrupt thresholds it will trigger an interrupt.
The circuit:
- Arduino Nano 33 BLE Sense
This example code is in the public domain.
*/
#include <Arduino_APDS9960.h>
int interrupt_pin = 2; // pin connected to the Interrupt pin from the sensor
// Thresholds to trigger the interrupt
unsigned int lower_threshold = 0;
unsigned int higher_threshold = 500;
// Flag to know if the interrupt has been triggered
int interrupt_flag = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
// Attach interrupt
attachInterrupt(interrupt_pin, assert_flag, FALLING);
if (!APDS.begin()) {
Serial.println("Error initializing APDS9960 sensor!");
}
//Enable the Light Interrupt generation on the Interrupt pin
APDS.enableLightInterrupt();
// Config the Thresholds
APDS.setLightLowThreshold(lower_threshold);
APDS.setLightHighThreshold(higher_threshold);
}
void loop() {
// Output the proximity
int r,g,b,c;
if (APDS.colorAvailable()) {
APDS.readColor(r, g, b,c);
}
Serial.println(c);
// If the interrupt flag has been asserted, clear the interrupt of the sensor
if ( interrupt_flag == 1 ) {
Serial.println("Flagged!");
delay(1000);
interrupt_flag = 0;
APDS.clearLightInterrupt();
Serial.println("Flag and interrupt cleared");
delay(5000);
}
delay(100);
}
void assert_flag() {
interrupt_flag = 1;
}