diff --git a/Digital_Light_TSL2561.cpp b/Digital_Light_TSL2561.cpp index 5a66057..77ff455 100755 --- a/Digital_Light_TSL2561.cpp +++ b/Digital_Light_TSL2561.cpp @@ -71,6 +71,44 @@ void TSL2561_CalculateLux::init() writeRegister(TSL2561_Address,TSL2561_Interrupt,0x00); writeRegister(TSL2561_Address,TSL2561_Control,0x00); // POWER Down } + + +uint16_t TSL2561_CalculateLux::readIRLuminosity() // read Infrared channel value only, not convert to lux. +{ + writeRegister(TSL2561_Address,TSL2561_Control,0x03); // POWER UP + delay(14); + getLux(); + + writeRegister(TSL2561_Address,TSL2561_Control,0x00); // POWER Down + if(ch1 == 0) + { + return 0; + } + if(ch0/ch1 < 2 && ch0 > 4900) + { + return -1; //ch0 out of range, but ch1 not. the lux is not valid in this situation. + } + return ch1; +} + +uint16_t TSL2561_CalculateLux::readFSpecLuminosity() //read Full Spectrum channel value only, not convert to lux. +{ + writeRegister(TSL2561_Address,TSL2561_Control,0x03); // POWER UP + delay(14); + getLux(); + + writeRegister(TSL2561_Address,TSL2561_Control,0x00); // POWER Down + if(ch1 == 0) + { + return 0; + } + if(ch0/ch1 < 2 && ch0 > 4900) + { + return -1; //ch0 out of range, but ch1 not. the lux is not valid in this situation. + } + return ch0; +} + signed long TSL2561_CalculateLux::readVisibleLux() { writeRegister(TSL2561_Address,TSL2561_Control,0x03); // POWER UP diff --git a/Digital_Light_TSL2561.h b/Digital_Light_TSL2561.h index 8546464..0300929 100755 --- a/Digital_Light_TSL2561.h +++ b/Digital_Light_TSL2561.h @@ -104,6 +104,8 @@ class TSL2561_CalculateLux { public: signed long readVisibleLux(); + uint16_t readIRLuminosity(); + uint16_t readFSpecLuminosity(); unsigned long calculateLux(unsigned int iGain, unsigned int tInt,int iType); void getLux(void); void init(void); diff --git a/examples/Digital_Light_Sensor_IR/Digital_Light_Sensor_IR.ino b/examples/Digital_Light_Sensor_IR/Digital_Light_Sensor_IR.ino new file mode 100644 index 0000000..51829bb --- /dev/null +++ b/examples/Digital_Light_Sensor_IR/Digital_Light_Sensor_IR.ino @@ -0,0 +1,48 @@ +/* + * Digital_Light_Sensor.ino + * A library for TSL2561 + * + * Copyright (c) 2019 seeed technology inc. + * Website : www.seeed.cc + * Author : hongtai.liu + * Create Time: 6/11/2019 + * Change Log : + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +void setup() +{ + Wire.begin(); + Serial.begin(9600); + TSL2561.init(); +} + +void loop() +{ + Serial.print("The Infrared value is: "); + Serial.println(TSL2561.readIRLuminosity()); //read Infrared channel value only, not convert to lux. + Serial.print("The Full Spectrum value is: "); + Serial.println(TSL2561.readFSpecLuminosity());///read Full Spectrum channel value only, not convert to lux. + delay(1000); +} diff --git a/keywords.txt b/keywords.txt index f1cab1c..edba1e0 100644 --- a/keywords.txt +++ b/keywords.txt @@ -23,7 +23,8 @@ DigitalLightISL29035 KEYWORD2 setFullScaleLuxRangeIndex KEYWORD2 setIntegrationTimeIndex KEYWORD2 readVisibleLux KEYWORD2 -readIRLux KEYWORD2 +readIRLuminosity KEYWORD2 +readFSpecLuminosity KEYWORD2 readEV KEYWORD2 test KEYWORD2