do nothing for roughly 2 hours
then slowly spin up motor (code above is about right)
stop motor when pinX is connected to ground after XX milliseconds
(pin will most likely remain connected to ground until motor spins again)
I also want to build in some safety in the form of never run the motor for longer then xx milliseconds.
If there is a similar project out there feel free to point me in that direction. I will continue to search for it in the meantime.
enable the pin change interrupt for pinX (which is moded as INPUT_PULLUP)
....
If the interrupt fires or the timer runs out (whichever comes first), turn the motor off, clear the flag, reset the timer and turn it off and disable the pin change interrupt.
I think you can solve your probkem witch free timers.
First is 2 hours long timer that switchs on the motor.
The other one is the safety timer than switchs off the motor compolsory after a few milliseconds
The third is a like timer that count the time when the button is pressed (or everyway the pin is connected to grd.
At the beginning the motor is stopped
You start first timer
At its and you start the motor, restart the long timer, and start the second one.
Every loop() you vontroll the pin, and if it is NOT vlnnected to gnd youbstart the third timer, so the only moment when the time runs is when the pin IS connected co gnd.
After it you check if the second or the third timer is passed. If so you stopped the motor.
Every timer have a specific variable, and "start" it means equal that variable to millis().
I think I followed that logic. I am looking into how to code with multiple timers now.
Silente:
I think you can solve your probkem witch free timers.
First is 2 hours long timer that switchs on the motor.
The other one is the safety timer than switchs off the motor compolsory after a few milliseconds
The third is a like timer that count the time when the button is pressed (or everyway the pin is connected to grd.
At the beginning the motor is stopped
You start first timer
At its and you start the motor, restart the long timer, and start the second one.
Every loop() you vontroll the pin, and if it is NOT vlnnected to gnd youbstart the third timer, so the only moment when the time runs is when the pin IS connected co gnd.
After it you check if the second or the third timer is passed. If so you stopped the motor.
Every timer have a specific variable, and "start" it means equal that variable to millis().