we need to be able to calibrate the light sensor in realtime. I suggest the following:
1.) create a new light sensor calibration function to execute in its own thread. Its purpose is to take a reading from the light sensor and store the value as the "black light value" in some variable. The function should move the light sensor to its reading position, take a reading, return the light sensor to its original position, and return as soon as it's done.
2.) determine the relationship between the value we read as "black" and the value we read as "white" under different lighting conditions to come up with a safe "delta" value (the difference in readings between "black" and "white") that applies in extreme light and dark conditions. Configure the value, the "light delta", in a macro or constant variable.
3.) change the code that reads the light sensor to look for the black value plus the delta value.
NOTE: it's possible that you may find there is no single delta value that applies in all lighting conditions...if that's the case, you might need multiple delta values that are used based on the black value falling into one of multiple ranges.
we need to be able to calibrate the light sensor in realtime. I suggest the following:
1.) create a new light sensor calibration function to execute in its own thread. Its purpose is to take a reading from the light sensor and store the value as the "black light value" in some variable. The function should move the light sensor to its reading position, take a reading, return the light sensor to its original position, and return as soon as it's done. 2.) determine the relationship between the value we read as "black" and the value we read as "white" under different lighting conditions to come up with a safe "delta" value (the difference in readings between "black" and "white") that applies in extreme light and dark conditions. Configure the value, the "light delta", in a macro or constant variable. 3.) change the code that reads the light sensor to look for the black value plus the delta value.
NOTE: it's possible that you may find there is no single delta value that applies in all lighting conditions...if that's the case, you might need multiple delta values that are used based on the black value falling into one of multiple ranges.