-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.ino
48 lines (37 loc) · 1.3 KB
/
light.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
#define LUX_SDA 20
#define LUX_SCL 21
// via __ Adafruit Example for demonstrating the TSL2561 library - public domain!
TSL2561 tsl(TSL2561_ADDR_FLOAT);
//-------------------------------------------------------
void setup_light(){
if (tsl.begin()) Serial.print("Light Sensor Ready...");
//else _reset();
delay(100);
tsl.setGain(TSL2561_GAIN_16X);
tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS);
}
//-------------------------------------------------------
Light get_light(){
Light l;
l.lum = tsl.getFullLuminosity();
l.ir = l.lum >> 16;
l.full = l.lum & 0xFFFF;
l.visible = l.full- l.ir;
l.lux = tsl.calculateLux(l.full, l.ir);
return l;
}
//-------------------------------------------------------
void print_light( Light _l ){
Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Serial.print("Lum: ");Serial.print(_l.lum); Serial.print("\t");
delay(100);
Serial.print("IR: "); Serial.print(_l.ir); Serial.print("\t");
delay(100);
Serial.print("Full: "); Serial.print(_l.full); Serial.print("\t");
delay(100);
Serial.print("Visible: "); Serial.print(_l.visible); Serial.print("\t");
delay(100);
Serial.print("Lux: "); Serial.println(_l.lux);
delay(100);
Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}