/Modules/Sensors/ISL2902001A/SW/Arduino/i2c_light/i2c_light.pde
1,7 → 1,6
// I2C Light Sensor
 
#include <Wire.h>
#include <math.h>
 
#define address 0x44 // A0 = L
#define SENSE_VIS 0
19,7 → 18,6
}
 
int data = 0;
int light_sensor_setup;
 
void led_blink()
{
73,12 → 71,12
Serial.print(data, BIN);
}
Wire.endTransmission(); // stop transmitting
light_sensor_setup=command;
 
}
 
float get_light_measurement()
int get_light_measurement()
{
int ret=0;
int lux=0;
 
// Connect to device and set register address
Wire.beginTransmission(address);
88,8 → 86,9
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
ret = Wire.receive();
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
lux=data;
// Connect to device and set register address
Wire.beginTransmission(address);
99,10 → 98,11
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
ret +=256 * Wire.receive();
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
 
return (1000.0/pow(2.0,16)*ret);
lux+=data*256;
return lux;
}
 
void loop()
112,11 → 112,11
set_light_sensor(SENSE_VIS); //setup sensor for visible measuring
led_blink(); // Delay for measurement
Serial.print("lux=");
Serial.println(get_light_measurement(),2);
Serial.println((unsigned)get_light_measurement(), DEC);
 
set_light_sensor(SENSE_IR); // setup sensor for infrared measuring
led_blink(); // Delay for measurement
Serial.print("luxIR=");
Serial.println(get_light_measurement(), 2); // data print
Serial.println((unsigned)get_light_measurement(), DEC); // data print
}