Skip to content

Commit e82486d

Browse files
committed
added examples for sensor's calibration
1 parent 3fd1bf1 commit e82486d

File tree

3 files changed

+133
-4
lines changed

3 files changed

+133
-4
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Arduino LTR381RGB - Measure Calibration Parameters
3+
4+
This example shows have to be used to measure the calibration parameters.
5+
The calibration parameters are the maximum and minimum values for each
6+
color channel.
7+
8+
To calculate the calibration parameters follow the steps below:
9+
- Turn Off all the lights and let the sketch measure the minimum R, G, B
10+
light intensity.
11+
- Turn On the light RGB channel one at a time and with the light channels
12+
set to the maximum brightness let the sketch measure the maximum R, G
13+
and B values.
14+
- Take note of the maximum and minimum values and use them in the
15+
ReadCalibratedColors example.
16+
17+
This example code is in the public domain.
18+
*/
19+
20+
#include "Arduino_LTR381RGB.h"
21+
22+
int maxR = 0;
23+
int maxG = 0;
24+
int maxB = 0;
25+
26+
int minR = 255;
27+
int minG = 255;
28+
int minB = 255;
29+
30+
void setup() {
31+
Serial.begin(9600);
32+
while (!Serial);
33+
34+
if (!RGB.begin()) {
35+
Serial.println("Failed to initialize rgb sensor!");
36+
while (1);
37+
}
38+
}
39+
40+
void loop() {
41+
int r, g, b;
42+
43+
if (RGB.readColors(r, g, b)) {
44+
if (r > maxR) {
45+
maxR = r;
46+
}
47+
if (r < minR) {
48+
minR = r;
49+
}
50+
if (g > maxG) {
51+
maxG = g;
52+
}
53+
if (g < minG) {
54+
minG = g;
55+
}
56+
if (b > maxB) {
57+
maxB = b;
58+
}
59+
if (b < minB) {
60+
minB = b;
61+
}
62+
Serial.print("Max Red: ");
63+
Serial.print(maxR);
64+
Serial.print("\tMin Red: ");
65+
Serial.print(minR);
66+
Serial.print("\tMax Green: ");
67+
Serial.print(maxG);
68+
Serial.print("\tMin Green: ");
69+
Serial.print(minG);
70+
Serial.print("\tMax Blue: ");
71+
Serial.print(maxB);
72+
Serial.print("\tMin Blue: ");
73+
Serial.println(minB);
74+
}
75+
76+
}

examples/ReadAllSensors/ReadAllSensors.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,24 @@ void setup() {
2525
}
2626

2727
void loop() {
28-
int r, g, b, rawlux;
29-
int lux;
28+
int r, g, b, rawlux, lux, ir;
29+
30+
if (RGB.readIR(ir)) {
31+
Serial.print("IR: ");
32+
Serial.print(ir);
33+
Serial.println();
34+
}
3035

3136
if (RGB.readAmbientLight(lux)) {
3237
Serial.print("Raw Lux: ");
3338
Serial.print(rawlux);
34-
Serial.print("\t");
39+
Serial.println();
3540
}
3641

3742
if (RGB.readLux(lux)) {
3843
Serial.print("Lumen: ");
3944
Serial.print(lux);
40-
Serial.print("\t");
45+
Serial.println();
4146
}
4247

4348
if (RGB.readColors(r, g, b)) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Arduino LTR381RGB - Read Calibrated colors
3+
4+
This example show how to set calibration values and reads
5+
the RGB channels values from the LTR381RGB sensor and continuously
6+
prints them to the Serial Monitor or Serial Plotter.
7+
8+
The calibration parameters have to be calculated using the
9+
MeasureCalibrationParameters example.
10+
11+
This example code is in the public domain.
12+
*/
13+
14+
#include "Arduino_LTR381RGB.h"
15+
16+
// Modify these values with the calibration parameters
17+
#define MAX_RED 255;
18+
#define MAX_GREEN 255;
19+
#define MAX_BLUE 255;
20+
#define MIN_RED 0;
21+
#define MIN_GREEN 0;
22+
#define MIN_BLUE 0;
23+
24+
void setup() {
25+
Serial.begin(9600);
26+
while (!Serial);
27+
28+
if (!RGB.begin()) {
29+
Serial.println("Failed to initialize rgb sensor!");
30+
while (1);
31+
}
32+
RGB.setCalibrations(MAX_RED, MAX_GREEN, MAX_BLUE, MIN_RED, MIN_GREEN, MIN_BLUE);
33+
}
34+
35+
void loop() {
36+
int r, g, b;
37+
38+
if (RGB.readColors(r, g, b)) {
39+
Serial.print("Red: ");
40+
Serial.print(r);
41+
Serial.print("\tGreen: ");
42+
Serial.print(g);
43+
Serial.print("\tBlue: ");
44+
Serial.println(b);
45+
}
46+
47+
delay(1000);
48+
}

0 commit comments

Comments
 (0)