24,8 → 24,8 |
#define LIGHT_ENABLE 1 |
#define LIGHT_DISABLE 0 |
|
#define LIGHT_MEASUREMENT_ONETIME 0 |
#define LIGHT_MEASUREMENT_CONTINUOUS 1 |
#define LIGHT_ONETIME 0 |
#define LIGHT_CONTINUOUS 1 |
|
#define LIGHT_SENSE_VIS 0 |
#define LIGHT_SENSE_IR 1 |
37,12 → 37,12 |
#define LIGHT_TIMING_EXTERNAL_ADC 0b100 |
#define LIGHT_TIMING_EXTERNAL_TIMER 0b101 |
|
#define LIGHT_AUTORANGE 0 |
//#define LIGHT_AUTORANGE 0 |
|
#define LIGHT_RANGE1 1 |
#define LIGHT_RANGE2 2 |
#define LIGHT_RANGE3 3 |
#define LIGHT_RANGE4 4 |
#define LIGHT_RANGE1 0b00 |
#define LIGHT_RANGE2 0b01 |
#define LIGHT_RANGE3 0b10 |
#define LIGHT_RANGE4 0b11 |
|
char filename[13]; |
int data = 0; |
94,34 → 94,19 |
{ |
int command=0; |
|
commad= (en << 7 & 0b10000000); |
|
switch (light) |
{ |
case LIGHT_SENSE_VIS: |
{ |
command=0b11000000; // setup (eye light sensing; one time measurement; measurement range 1) |
break; |
} |
command = (command & 0b01111111) | (en << 7); |
command = (command & 0b10111111) | (mode << 6); |
command = (command & 0b11011111) | (light << 5); |
command = (command & 0b11100011) | (res << 2); |
command = (command & 0b11111100) | (range); |
|
case LIGHT_SENSE_IR: |
{ |
command=0b11100000; // setup (eye light sensing; measurement range 2 [4000 lx]) |
break; |
} |
|
default: |
return 3; |
} |
|
// Setup device |
Wire.beginTransmission(address); |
Wire.send(0x00); // sends address |
Wire.send(command); // setup (eye light sensing; one time measurement; measurement range 1) |
Wire.endTransmission(); // stop transmitting |
|
|
// Connect to device and set register address |
|
// Connect to device and set register address |
Wire.beginTransmission(address); |
Wire.send(0x00); // sends address (command register) |
Wire.endTransmission(); // stop transmitting |
131,11 → 116,13 |
Wire.requestFrom(address, 1); |
if (command != Wire.receive()) |
{ |
Serial.println(data, BIN); |
Serial.println("Error in sensor setting"); |
return 4; |
} |
Wire.endTransmission(); // stop transmitting |
light_sensor_setup=command; |
Serial.println(command, BIN); |
|
return 0; |
} |
|
148,7 → 135,7 |
Wire.send(0x01); // sends address of LSB reagister |
Wire.endTransmission(); // stop transmitting |
|
// Connect to device and request one byte |
// Connect to device and request first byte |
Wire.beginTransmission(address); |
Wire.requestFrom(address, 1); |
ret = Wire.receive(); |
159,13 → 146,13 |
Wire.send(0x02); // sends address of MSB register |
Wire.endTransmission(); // stop transmitting |
|
// Connect to device and request one byte |
// Connect to device and request second byte |
Wire.beginTransmission(address); |
Wire.requestFrom(address, 1); |
ret +=256 * Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
|
return (1000.0/pow(2.0,16)*ret); |
return (64000.0/pow(2.0,16)*ret); |
} |
|
void loop() |
174,13 → 161,13 |
float luxIR=0; |
float time; |
|
set_light_sensor(LIGHT_SENSE_VIS); //setup sensor for visible measuring |
set_light_sensor(LIGHT_ENABLE, LIGHT_ONETIME, LIGHT_SENSE_VIS, LIGHT_TIMING_INTERNAL_16, LIGHT_RANGE4); //setup sensor for visible measuring |
led_blink(); // Delay for measurement |
luxVIS=get_light_measurement(); |
|
time=millis()/1000.0; |
|
set_light_sensor(LIGHT_SENSE_IR); // setup sensor for infrared measuring |
set_light_sensor(LIGHT_ENABLE, LIGHT_ONETIME, LIGHT_SENSE_IR, LIGHT_TIMING_INTERNAL_16, LIGHT_RANGE4); // setup sensor for infrared measuring |
led_blink(); // Delay for measurement |
luxIR=get_light_measurement(); |
|