Hello, I am a programmer/hacker that has been working on the Raspberry-Pi for some time now using python to program a project I am working on. At this point in that project, I would like to utilize an ATtiny to trigger physical and software shutdowns of the raspberry pi. The main inspiration for this is the typical PC-Laptop, where you have a button to press for a duration of time(I assume there is some sort of micro-controller behind this, which is independent from the OS-system) which forces the Laptop to power down. This physical shutdown option is good, as I personal know from experience that commanding a system to shutdown through and OS-GUI or command-line interface environment doesn't always work, especially in cases where the OS has frozen or something.
To replicate this, I have started developing a prototype which uses an ATtiny85(In my final draft of all this, I will most likely use a smaller chip, with the primary factor being that I doubt this project needs more than 0.5kb, so I am eyeing the ATtiny4 right now.) with one input, PB4, for the MC to listen for the software shutdown("...I told the Pi to shutdown from within Raspbian."), and another input, PB2, to listen for the physical shutdown("...I push down on a button for about to seconds, just as you would a laptop.").
In the previous version of this prototype, things were simpler and more isolated. First off, the ATtiny85 wasn't always powered on because I hadn't included the software shutdown option, and all I did was hold a button for about two seconds and used _delay_ms to delay the output I needed.
Now though I want to use a small button battery to keep the chip running, so with this, the steps of my previous algorithm wont work, a simple delay at start of script won't work. As I stated in my opening, I am more familiar with hardware such as the Pi and programming language of choice is Python. What I need help with is figuring out a C code statement which represents a logical if-then statement such as:
p= PB2 has been high for two seconds or more.
q= PB5 is high
"If time high of PB2 is equal to or greater than 2 seconds then PB5 is high."
With C code and my ATtiny85, how could I implement this? How could I initiate and measure the amount of time that an input pin is high or low?