I’m having a hard time finding help on this because I’m not even sure how to search for it, but here’s what I want to solve.
I have a photon that will be running in my truck to control a raspberry pi’s power on and off. Essentially when the ignition power is present, the Pi will power up, but when the ignition goes off, I want to signal the Pi to do a graceful shutdown. I’m doing this with a relay board I have connected to the Photon.
Here’s the scenario: ignition on isn’t a problem, all i’m doing is having the photon sense the ignition with a voltage divider on a digital pin set to detect high or low voltage. I then trigger another pin set as output to trigger a relay that sends 5v power to the Pi. When the ignition goes off I sense this with the photon (that has contant power) and then issue a signal on the other pin that is connected to one of the Pi’s GPIO pins where I have a python script to do a graceful shutdown.
My plan was to be able to have a certain delay of say 20 minutes to leave the Pi powered up in case I’m just quickly stopping somewhere so I don’t have to keep rebooting it all the time. The problem is the if…else loop I have has no way to interrupt the shutdown sequence when ignition power is restored. Should I be using a while loop or a do while or a switch setup? Which one of these control structures will interrupt the current case when conditions change?