/Modules/Sensors/ISL2902001A/SW/Arduino/i2c_light/i2c_light.pde
17,82 → 17,77
 
int data = 0;
 
void loop()
void led_blink()
{
int lux=0;
digitalWrite(3, HIGH); // set the LED on
delay(500);
digitalWrite(3, LOW); // set the LED off
delay(500);
}
 
/* Serial.print("lux=");
 
int set_light_sensor()
{
// Setup device
digitalWrite(5, HIGH);
 
Wire.beginTransmission(address);
Wire.send(0x00); // sends address
Wire.send(0b11000000); // setup (eye light sensing; one time measurement; measurement range 1)
Wire.send(0b11100000); // setup (eye light sensing; measurement range 2 [4000 lx])
Wire.endTransmission(); // stop transmitting
 
// Delay for measurement
}
 
digitalWrite(5, LOW); // set the LED off
delay(500);
digitalWrite(5, HIGH); // set the LED on
delay(500);
int get_light_measurement()
{
int lux=0;
 
// Connect to device and set register address
Wire.beginTransmission(address);
Wire.send(0x00); // sends address
Wire.send(0x01); // sends address of LSB reagister
Wire.endTransmission(); // stop transmitting
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
// Serial.print(data, HEX);
 
// Serial.print(" LSB=");
// Connect to device and set register address
Wire.beginTransmission(address);
Wire.send(0x01); // sends address
Wire.endTransmission(); // stop transmitting
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
// Serial.print(data, HEX);
lux=data;
 
// Serial.print(" MSB=");
// Connect to device and set register address
Wire.beginTransmission(address);
Wire.send(0x02); // sends address
Wire.send(0x02); // sends address of MSB register
Wire.endTransmission(); // stop transmitting
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
// Serial.print(data, HEX);
 
lux+=data*256;
*/
return lux;
}
 
Serial.print((unsigned)lux, DEC);
void loop()
{
int lux=0;
Serial.print(" luxIR=");
/* Serial.print("lux=");
// Setup device
digitalWrite(5, HIGH);
 
Wire.beginTransmission(address);
Wire.send(0x00); // sends address
Wire.send(0b11100000); // setup (eye light sensing; measurement range 2 [4000 lx])
Wire.send(0b11000000); // setup (eye light sensing; one time measurement; measurement range 1)
Wire.endTransmission(); // stop transmitting
// Delay for measurement
digitalWrite(3, HIGH); // set the LED on
 
digitalWrite(5, LOW); // set the LED off
delay(500);
digitalWrite(3, LOW); // set the LED off
digitalWrite(5, HIGH); // set the LED on
delay(500);
// Connect to device and set register address
Wire.beginTransmission(address);
Wire.send(0x00); // sends address
129,6 → 124,27
Wire.endTransmission(); // stop transmitting
// Serial.print(data, HEX);
lux+=data*256;
Serial.println((unsigned)lux, DEC);
 
Serial.print((unsigned)lux, DEC);
*/
 
set_light_sensor();
// Delay for measurement
led_blink();
// Connect to device and set register address
Wire.beginTransmission(address);
Wire.send(0x00); // sends address
Wire.endTransmission(); // stop transmitting
// Connect to device and request one byte
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
data = Wire.receive();
Wire.endTransmission(); // stop transmitting
 
// data print
Serial.print(" luxIR=");
Serial.println((unsigned)get_light_measurement(), DEC);
}