forked from hideakitai/TCS34725
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTCS34725_Interrupt_Thresholds.ino
47 lines (40 loc) · 1.13 KB
/
TCS34725_Interrupt_Thresholds.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
#include "TCS34725AutoGain.h"
TCS34725 tcs;
void setup() {
Serial.begin(115200);
Serial.println();
Wire.begin();
if (!tcs.attach()) {
Serial.println("Error, no TCS detected");
return;
}
tcs.autoGain();
Serial.print("Autogain has selected gain x");
Serial.print(tcs.gain());
Serial.print(", integration time ");
Serial.print(tcs.integrationTime());
Serial.println("ms, beginning measurements:");
// don't generate an interrupt on every completed read, but only for reads
// whose clear count was outside the threshold range
tcs.persistence(0x01);
}
void loop() {
TCS34725::RawData raw = tcs.raw();
// calculate +- 20% thresholds
uint16_t low = raw.c * .8;
uint16_t high = raw.c * 1.2;
tcs.interruptThresholds(low, high);
Serial.print("Raw clear count: ");
Serial.print(raw.c);
Serial.print(", waiting for interrupt indicating a measurement outside [");
Serial.print(low);
Serial.print(", ");
Serial.print(high);
Serial.println("].");
// poll for next out-of-threshold read
while (!tcs.available()) {
Serial.print('.');
delay(tcs.integrationTime());
}
Serial.println('!');
}