@@ -67,7 +67,11 @@ void configureSensor(int choice)
67
67
tsl.setGain (TSL2591_GAIN_HIGH); // 428x gain
68
68
tsl.setTiming (TSL2591_INTEGRATIONTIME_600MS); // longest integration time
69
69
hysteresis = 1.1 ;
70
- } // The device's gain can go up to 9876, but measurements with that setting seem unreliable, and there doesn't seem to be a need anyway.
70
+ } else if (choice == 4 ) {
71
+ tsl.setGain (TSL2591_GAIN_MAX); // 9876x gain
72
+ tsl.setTiming (TSL2591_INTEGRATIONTIME_600MS); // longest integration time
73
+ hysteresis = 1.4 ;
74
+ }
71
75
garbage = true ; // The next measurement will be bad, and should be thrown out.
72
76
}
73
77
@@ -111,12 +115,14 @@ bool advancedRead(void)
111
115
double newLux = tsl.calculateLux ((lum & 0xFFFF ), (lum >> 16 ));
112
116
113
117
// Interpret the measurement and decide if the gain should be adjusted
114
- if (newLux == 0 || newLux > 60000 ) { // The sensor saturated or is close
118
+ if (newLux == 0 || newLux > 60000 ) { // The sensor saturated (leading to a returned zero) or is close
115
119
if (settingsCounter > 0 ) {
116
120
newSetting = settingsCounter - 1 ; // Decrease the gain
117
121
}
118
122
} else if (newLux > 1700 * hysteresis) {
119
123
newSetting = 1 ; // Use low gain setting
124
+ } else if (newLux < 5 * hysteresis) {
125
+ newSetting = 4 ; // Highest gain setting
120
126
} else if (newLux < 100 * hysteresis) {
121
127
newSetting = 3 ; // Use high gain setting
122
128
} else {
@@ -157,7 +163,7 @@ void loop(void)
157
163
Serial.print (" [ " ); Serial.print (millis ()); Serial.print (" ms ] " );
158
164
Serial.print (" IR: " ); Serial.print (ir); Serial.print (" " );
159
165
Serial.print (" Visible: " ); Serial.print (visible); Serial.print (" " );
160
- Serial.print (" Lux: " ); Serial.print (lux); Serial.print (" " );
166
+ Serial.print (" Lux: " ); Serial.print (lux, 4 ); Serial.print (" " ); // Print lux to 4 decimal places
161
167
Serial.print (" Gain Config: " ); Serial.println (settingsCounter);
162
168
}
163
169
}
0 commit comments