use of signal edge detection with a pushbutton and canceling an external trigger

Howdy!

I've been working on a project to get an output to light using a pushbutton with signal edge detection with the following code:

/ One Button On/Off Toggle
// Photos are in attached file for wiring of the circuit on the breadboard, adjacent to this file

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 10;    // the debounce time; increase if the output flickers

const int Button7 = 3;               // the number of the momentary button pin
const int OutputGround7 =  8;      // the number of the output pin, or load trigger pin

int OutputGround7State = LOW;         // the current state of the output pin
int Button7State = LOW;             // the current reading from the input pin
int PreviousButton7State = HIGH;   // the previous reading from the input pin
int Reading7;

void setup() {
  pinMode(Button7, INPUT);
  pinMode(OutputGround7, OUTPUT);
}

void loop() {
              
  Reading7 = digitalRead(Button7);
   if (Reading7 != PreviousButton7State) {
      lastDebounceTime = millis();
      PreviousButton7State = Reading7;
   } 

   if ((millis() - lastDebounceTime) > debounceDelay) {
       if (Button7State != PreviousButton7State) {
           Button7State = PreviousButton7State;
           if (Button7State == HIGH) {
                 OutputGround7State = !OutputGround7State;
                 digitalWrite(OutputGround7, OutputGround7State);
                  
           }
       }
   }
}

What I would like to do is to have a switch in tandem to this momentary push button that can be either on or off (non-momentary, or SPST)

I've gotten the code along this far, but i don't know where to add the if statements without messing up what i've already written.

Essentially the situation goes as follows:

Case 1: The SPST switch is thrown ON, but the user wants to temporarily cancel that switch being thrown on, so they press the momentary switch (the switches may not be in the same location such as on the breadboard in the schematic), and the output turns off, but the SPST switch is still turned on. The user then turns the SPST switch off and the whole system is off.

Case 2: The user wants to simply turn the output on (without sliding the SPST), so they press the momentary switch, the output turns on, user wants the output off, so they press the momentary switch again and the whole system is off. (this is what I have figured out with the above code)

Case 3: The user presses the momentary switch, such that the output is on, but then the user turns on the SPST switch, user wants to turn the system off all together, so they slide the SPST switch , and the whole system is off. (no need to press the momentary push button)

Case 4: The user wants the output turned on just with the SPST switch, so they slide the switch to on, the output is on, user wants the output off, slides the switch to off. (no use of the momentary pushbutton) (this case is easy to do do on a breadboard without the arduino, but difficult to integrate with the use of a tandem pushbutton)

I would like to use D13 as the 5V trigger from the SPST switch.

Schematic attached below.

Thanks for the help, and I'll clarify the best I can :slight_smile:

Case 1, what happens if I press the button again?

Case 2, what happens if I slide the switch?

Case 3, what happens if I press the button?

Case 4, what happens if I press the button?

In any case… what happens if I hold the button and slide the switch?

But my real question is what's better, aspirin or acetaminophen?

c7