Multiple Inputs

Hello everyone having an issue figuring this one out and need some help. How do I write a IF command to monitor 2 inputs to control 1 output when both inputs don't come in at the same time. So if I want to trigger the output when it receives the 2 inputs but they are 3 seconds apart, is it possible to hold one for 5 seconds to give the other time to come in if so how do you write the program? Thank you

WOW Thank you everyone for responding to the posting. I can't wait to try the new program thank you again. Arduino is really the best because of the users helping users. Awesome!!!!!

Can you please explain more clearly what you want to do ?

Is switch 1 held on and then you wait for switch 2 or can switch 1 be pressed and released and switch 2 pressed within a time limit ? If the latter, then if switch 2 is not pressed within the time period should the system forget the switch 1 press and start waiting for it again ?

jxs058959: Hello everyone having an issue figuring this one out and need some help. How do I write a IF command to monitor 2 inputs to control 1 output when both inputs don't come in at the same time. So if I want to trigger the output when it receives the 2 inputs but they are 3 seconds apart, is it possible to hold one for 5 seconds to give the other time to come in if so how do you write the program? Thank you

Sounds like you will have to record the timestamps of the last change (or changes) on the various inputs and your condition will depend on the current state and time(s) of last changes?

I managed to do it in 6 if statements, not quite the 1 you were looking for, but I don’t think it is that simple…
I have even incorporated some debouncing for you.

const int ledPin =  13;      // the number of the LED pin
const int BUTTON1 =  2;      
const int BUTTON2 =  3;      

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);   
  pinMode(BUTTON1, INPUT);  
  pinMode(BUTTON2, INPUT);  
  digitalWrite(BUTTON1, HIGH); //Activate pullup
  digitalWrite(BUTTON2, HIGH); //Activate pullup
}

unsigned long button1Press;
unsigned long button2Press;
byte button1Pressed = 0;
byte button2Pressed = 0;

void loop()
{
  if ((digitalRead(BUTTON1) == LOW) && button1Pressed == 0) { //if this is the firt time out button is pressed, record the time.
    button1Press = millis();
    button1Pressed = 1;
  }
  if (digitalRead(BUTTON1) == HIGH) { //if our button is released, get ready for the next press
    button1Pressed = 0;
    digitalWrite(ledPin, LOW);
  }

  if ((digitalRead(BUTTON2) == LOW) && button2Pressed == 0) { //if this is the firt time out button is pressed, record the time.
    button2Press = millis();
    button2Pressed = 1;
  }
  if (digitalRead(BUTTON2) == HIGH) { //if our button is released, get ready for the next press
    button2Pressed = 0;
    digitalWrite(ledPin, LOW);
  }

  if ((button1Pressed == 1) && (button2Pressed == 1)
    && (millis() - button1Press > 20)  //20 millisecond debounce time
  && (millis() - button2Press > 20)) //20 millisecond debounce time
  {
    if (((button1Press - button2Press) < 5000) || ((button2Press - button1Press) < 5000)) {
      //Buttons are both depressed and it was done within 5 seconds of each other
      digitalWrite(ledPin, HIGH);
    } 
    else {
      //buttons are both depressed, but it took longer than 5 seconds
    }
  }
}