20,10 → 20,25 |
#define chipSelect 4 |
|
#define address 0x44 // A0 = L |
#define SENSE_VIS 0 |
#define SENSE_IR 1 |
|
#define LIGHT_ENABLE 1 |
#define LIGHT_DISABLE 0 |
|
#define LIGHT_MEASUREMENT_ONETIME 0 |
#define LIGHT_MEASUREMENT_CONTINUOUS 1 |
|
#define LIGHT_SENSE_VIS 0 |
#define LIGHT_SENSE_IR 1 |
|
#define LIGHT_TIMING_INTERNAL_16 0b000 |
#define LIGHT_TIMING_INTERNAL_12 0b001 |
#define LIGHT_TIMING_INTERNAL_8 0b010 |
#define LIGHT_TIMING_INTERNAL_4 0b011 |
#define LIGHT_TIMING_EXTERNAL_ADC 0b100 |
#define LIGHT_TIMING_EXTERNAL_TIMER 0b101 |
|
#define LIGHT_AUTORANGE 0 |
|
#define LIGHT_RANGE1 1 |
#define LIGHT_RANGE2 2 |
#define LIGHT_RANGE3 3 |
75,19 → 90,21 |
delay(500); |
} |
|
int set_light_sensor(int mode) |
int set_light_sensor(int en, int mode, int light, int res, int range) |
{ |
int command; |
int command=0; |
|
commad= (en << 7 & 0b10000000); |
|
switch (mode) |
switch (light) |
{ |
case SENSE_VIS: |
case LIGHT_SENSE_VIS: |
{ |
command=0b11000000; // setup (eye light sensing; one time measurement; measurement range 1) |
break; |
} |
|
case SENSE_IR: |
case LIGHT_SENSE_IR: |
{ |
command=0b11100000; // setup (eye light sensing; measurement range 2 [4000 lx]) |
break; |
114,11 → 131,12 |
Wire.requestFrom(address, 1); |
if (command != Wire.receive()) |
{ |
Serial.println(data, BIN); |
return 4; |
Serial.print(data, BIN); |
} |
Wire.endTransmission(); // stop transmitting |
light_sensor_setup=command; |
return 0; |
} |
|
float get_light_measurement() |
156,13 → 174,13 |
float luxIR=0; |
float time; |
|
set_light_sensor(SENSE_VIS); //setup sensor for visible measuring |
set_light_sensor(LIGHT_SENSE_VIS); //setup sensor for visible measuring |
led_blink(); // Delay for measurement |
luxVIS=get_light_measurement(); |
|
time=millis()/1000.0; |
|
set_light_sensor(SENSE_IR); // setup sensor for infrared measuring |
set_light_sensor(LIGHT_SENSE_IR); // setup sensor for infrared measuring |
led_blink(); // Delay for measurement |
luxIR=get_light_measurement(); |
|