A bulk of the code in both chapter09/ldr_ads1115_calibrate.py and chapter09/ldr_ads1115_calibrate.py is the boilerplate code to set up and configure the ADS1115 and set up the LED using PiGPIO. We will not recover the common code here. If you need a refresher on the ADS1115-related code, please review the exercise found in Chapter 5, Connecting Your Raspberry Pi to the Physical World.
Let's look at the Python code that makes our LDR work.
In line 1, we see that we are importing the ldr_calibration_config.py file that we created with our calibration program previously.
Next, in line 2, we are assigning the calibration values to the LIGHT_VOLTS (the voltage detected by the ADS1115 when the LDR was in the light) and DARK_VOLTS (the voltage detected when you covered up the LDR)Â variables:
import ldr_calibration_config as calibration # (1)
# ... truncated ...
LIGHT_VOLTS = calibration.MAX_VOLTS ...