Automatic switch based on environment lighting

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 ...

Get Raspberry Pi 3 Projects for Java Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.