I have just started with Arduino this week. Doing lots of reading and research, its alot to take in all at once. But if I remember 1 thing each time I do something, I'll be good to go.
What i am working on now is controlling 2 or more relays that shut off at separate times. IE both relays turn on at once, relay 1 turns off after 5 seconds, 2nd relay turns off after 20 seconds.
How can I get the loop to restart if there is a button press in between the 1st relay off and the 2nd relay off.
int pinButton = 12;
int Relay = 2;
int Relay2 = 3;
int stateRelay = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayON = 5000; //stay on for 5000 ms
int stayON2 = 15000;
PS: Technically, you don't want or need an interrupt, that might sound like an applicable term but it may mean something different than what you think. Interrupt - Wikipedia
State machines might sound daunting but are, in principle, quite simple.
Your project has 3 states
0 - both relays off and waiting
1 - relay 1 on for a period
2 - both relays on for a period
Using switch/case seems to make state machines easier to understand, at least for me. Set a variable, let's call it state, to 0 and use the state variable in switch/case.
start of loop()
switch using state
case 0:
if it is time for relay 1 to turn on
turn on relay 1
set state to 1
note the time using millis()
case 1:
if it is time for relay 2 to turn on
turn on relay 2
set state to 2
note the time using millis()
case 2
if it is time to turn the relays off
turn the relays off
set state to 0
end of switch
if the 'abort' button is pressed
turn off both relays
set state to 0
end of loop()
All the timing must be done with millis() so that the program does not stop and wait and the 'abort' button can be tested each time through loop()