See if you can follow the following, it has a statemachine (switch-case) that 'walks' through the stages of how the system should behave.
Its a common way to code these types of things
State/Case 0: the system is OFF and in rest, we are waiting for someone to push a button.
If someone pushes button we switch on Relay and led and go to the next state
State/case 1: here we wait untill the button is released
if button is released we go to the next state.
State/case 2: here the system is ON and we are in rest, we are waiting for someone to push button
...etc....
/* Alternating LED's */
#include <Bounce.h>
const int inputPin = 2; // momentary switch
const int ledPin = 13; // the number of the LED pin
const int relayPin1 = 12;
const int relayPin2 = 11;
byte mode = 0;
Bounce bouncer = Bounce(inputPin,75); //settup debounce for first push button
void setup()
{ pinMode(inputPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
}
void loop() {
bouncer.update ( ); // Update the debouncer for the push button
switch( mode )
{
case 0://------------------------ I'm off and in restmode
if ( bouncer.read() == HIGH )
{ // switch relay ON
// switch LED ON
mode = 1;
}
break;
case 1://------------------------ I'm in ON mode, w8 4 keyrelease
if ( bouncer.read() == LOW )
mode = 2;
break;
case 2://------------------------ I'm ON and in restmode
if ( bouncer.read() == HIGH )
{ // switch relay OFF
// switch LED OFF
mode = 3;
}
break;
case 3://------------------------ I'm in OFF mode, w8 4 keyrelease
if ( bouncer.read() == LOW )
mode = 0;
break;
}//switch
}//loop
Code is untested and the case gives you the framework, still need to fill in the Relay ON/OFF and LED On/OFF