I found a glitch in the leak sensor I built. The valve I use to turn off the water incase of a leak has an open/close switch. To this switch I connected a red and a green LED. My thought was I would know things are running OK as long as the green LED was lit. Well we had a power outage and so the Pi shutdown without cleaning up the GPIO pins. Once the power came back the Pi booted and the green LED came on but my program was not running. Now my thought is to use PWM to pulse the LED. I am assuming if the Pi gets shutdown and restarted unexpectedly the PWM would not be working so the LED would just be on and not pulsing. Is that true?
I am also going to make a cron job so it launches the script on boot.
Now fo rate harder part. Ho who I keep the PWM looping while the rest of my program is running? The program monitors several GPIO pins to see if they are low or high every 5 minutes. If the condition changes it closes a valve and send me a text. Is there a clean way to run the loop pulsing the LED while the main program is sleeping? I guess I could run a loop pulsing the LED that would run for 5 minutes then exit and run the GPIO test. I was wondering if this would be a good case for threading? I have read some about it but don't yet have a good handle on making it work.
One last thing. If a leak is detected I poll the GPIO pin running the green LED to see if the valve is still open. If the PWM is running could that give a false reading on that GPIO pin?