Skip to content

Commit

Permalink
Add two APIs and a example.
Browse files Browse the repository at this point in the history
uint16_t readIRLuminosity(void), read Infrared channel value only, not convert to lux.
uint16_t readFSpecLuminosity(void) //read Full Spectrum channel value only,  not convert to lux.
  • Loading branch information
LynnL4 committed Jun 11, 2019
1 parent 84bcb8a commit 29e9a32
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
38 changes: 38 additions & 0 deletions Digital_Light_TSL2561.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Digital_Light_TSL2561.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 48 additions & 0 deletions examples/Digital_Light_Sensor_IR/Digital_Light_Sensor_IR.ino
Original file line number Diff line number Diff line change
@@ -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 <Wire.h>
#include <Digital_Light_TSL2561.h>
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);
}
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ DigitalLightISL29035 KEYWORD2
setFullScaleLuxRangeIndex KEYWORD2
setIntegrationTimeIndex KEYWORD2
readVisibleLux KEYWORD2
readIRLux KEYWORD2
readIRLuminosity KEYWORD2
readFSpecLuminosity KEYWORD2
readEV KEYWORD2
test KEYWORD2

Expand Down

0 comments on commit 29e9a32

Please sign in to comment.