A lux sensor library
Revision 3:5b5911bfc644, committed 2015-08-13
- Comitter:
- joshuasmth04
- Date:
- Thu Aug 13 15:00:29 2015 +0000
- Parent:
- 2:c45d34e9c3f0
- Commit message:
- Finished and fully working, Lux values are not verified with a outside source but rather taken from the data sheet. Auto-selects between low and high gain settings. Note readings can take up to 0.65 seconds each, currently take ~0.1-0.3.
Changed in this revision
TSL2561.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/TSL2561.cpp Wed Aug 12 19:57:46 2015 +0000 +++ b/TSL2561.cpp Thu Aug 13 15:00:29 2015 +0000 @@ -312,7 +312,8 @@ { uint32_t full_lums; //set to default gain (Note: going high gain to low is slower but more reliable, low gain to high gain is faster but less reliable) - setTimingGain(TSL2561_INTEGRATIONTIME_101MS, TSL2561_GAIN_16X); // start at high gain and long readings + setTimingGain(TSL2561_INTEGRATIONTIME_13MS, TSL2561_GAIN_16X); // start at high gain and long readings + wait(0.1);// give the TSL time to adjust, more time is more reliable but slower, less time lessreliable but faster //decreas gain/time if reading is to high (diable this block and change that^ line for fixed gain) //take reading read_again: @@ -321,18 +322,19 @@ channal1 = (full_lums >> 16); //If ir, or vis and ir, are within 5% of max then decreas the gain/time and repeat //Pick the corect time to match ^ - //if(((channal0 > 4794) | (channal1 > 4792)) & (_gain != TSL2561_GAIN_0X)){ //13ms - if(((channal0 > 35318) | (channal1 > 35318)) & (_gain != TSL2561_GAIN_0X)){ //101ms + if(((channal0 > 4794) | (channal1 > 4792)) & (_gain != TSL2561_GAIN_0X)){ //13ms + //if(((channal0 > 35318) | (channal1 > 35318)) & (_gain != TSL2561_GAIN_0X)){ //101ms //if(((channal0 > 62258) | (channal1 > 62258)) & (_gain != TSL2561_GAIN_0X)){ //402ms setTimingGain(_integration, TSL2561_GAIN_0X); + wait(0.1); // give the TSL time to adjust, more time is more reliable but slower, less time lessreliable but faster goto read_again; } //calculate lux from reading lux = calculateLux(channal0, channal1); - pc.printf("gain: %d time: %d, lux:%d\r\n", _gain, _integration, lux); - + //pc.printf("gain: %d time: %d, lux:%d\r\n", _gain, _integration, lux); + //pc.printf("ch0:%d, ch1: %d\r\n", channal0, channal1); }