In this section, we will be combining the built hardware components to automate the switching of the relay based on the environment lighting, including printing states to the LCD. Let's close all the code tabs in the editor and leave only the Main class open. If not already done, comment the relayExample(); method and uncomment the lightDependentSwitching() method. This last method will instantiate the LdrHandler class and pass on a RelaySwitch object. If you already have been playing with the darkThreshold member value in the LdrHandler class, you can press the Run application button and the application should start switching automatically and update the LCD statuses. When we play a little bit with the environment lighting by putting our hand over the LDR, the relay should close, and when light is reaching the LDR again, the relay should open.
We now have this...