Skip to content

Commit 5364d61

Browse files
committed
renanmed Read all sensors example
1 parent fc74734 commit 5364d61

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Arduino LTR381RGB - Read All Sensors
3+
4+
This example reads the RGB, raw lux and lux values from the LTR381RGB
5+
sensor and continuously prints them to the Serial Monitor
6+
or Serial Plotter.
7+
8+
The circuit:
9+
- Arduino Uno WiFi R4
10+
- Modulino light sensor
11+
12+
This example code is in the public domain.
13+
*/
14+
15+
#include "Arduino_LTR381RGB.h"
16+
17+
void setup() {
18+
Serial.begin(9600);
19+
while (!Serial);
20+
21+
if (!RGB.begin()) {
22+
Serial.println("Failed to initialize rgb sensor!");
23+
while (1);
24+
}
25+
}
26+
27+
void loop() {
28+
int r, g, b, rawlux;
29+
int lux;
30+
31+
if (RGB.readAmbientLight(lux)) {
32+
Serial.print("Raw Lux: ");
33+
Serial.print(rawlux);
34+
Serial.print("\t");
35+
}
36+
37+
if (RGB.readLux(lux)) {
38+
Serial.print("Lumen: ");
39+
Serial.print(lux);
40+
Serial.print("\t");
41+
}
42+
43+
if (RGB.readColors(r, g, b)) {
44+
Serial.print("Red: ");
45+
Serial.print(r);
46+
Serial.print("\tGreen: ");
47+
Serial.print(g);
48+
Serial.print("\tBlue: ");
49+
Serial.println(b);
50+
}
51+
delay(1000);
52+
}

0 commit comments

Comments
 (0)