Your intention to achieve a certain functionality and to read about a lot of different things is honorable. But using interrupts in this way is the most unsuitable one.
An interrupt does what its name says: interrupting code-execution. This interruption through an interrupt occurs on the lowest level. This means totally regardless of which command your code is executing at the moment the code will be interrupted. For example creating vacuum is started but sucker did not touch the object. If additionally you would stop code-execution in this moment even sensing a button to resume would have to be duplicated to be done in your
"interrupt is active waiting for resume-button-press"
Very ugly way to create the wanted functionality.
One basic property of a state-machine is:
quickly jump in, quickly jump out
quickly jump in, quickly jump out
quickly jump in, quickly jump out
quickly jump in, quickly jump out
this makes a state-machine very responsive to whatever input ever
This means at a minimum it jumps in / jumps out 100 times per second
it s very likely that it will jump in jump out 1000 times or even more per second.
And this quickly jump in / jump out will enable to always check a pause and a resume button
This means you get the function of pausing / resuming from everywhere in your code regardless of what your machine is doing in this moment.
And additionally you will win the option to
- depending on what your machine is doing in the moment the pause-button-press occurs -
to execute some quick additional steps before really pausing.
example switching off vacuum in case the sucker did not even start to move towards the object that shall be picked up
This is just an option. You don't have to.
And a state-machine will offer to memorise at what step the pausing occured and to continue after pressing the resume-button with exactly that step that shall hapen next
or
if you like to change with which step the machine shall continue
Once you have understood the concept of state-machine you never want to use something else again.
Another advantage of state-machines is that it minimizes the number of if-conditions to a minimum. This is caused through the
mutually exclusive code-execution that a state-machine offers
Every machine-control needs timing. There is a way for non-blocking timing that avoids all the disadvantages of delay() .
The combination of non-blocking timing combined with a
quickly jump in / quickly jump out
quickly jump in / quickly jump out
quickly jump in / quickly jump out
state-machine
offers all possabilities you are dreaming of
additionally it is very easy to maintain, to modify, to expand its functionalities.
Here is a demo-code that demonstrates how state-machines work
And here is a short tutorial that explains how non-blocking timing works
best regards Stefan