Do you know what 5 && 3 is? That is NOT how to read two pins. There are NO shortcuts. You have to read each of them separately. If the order matters, then you also need to keep track of when each pin BECOMES pressed (not IS pressed).
Does the first button have to remain pressed until the second one becomes pressed or can the first one be released but be "forgotten" 5 seconds later ?
Here is a program that does what you describe, albeit full of flaws, but it should give you some ideas
const byte buttonPin1 = A1;
const byte buttonPin2 = A2;
unsigned long waitStart;
unsigned long currentMillis;
unsigned long period = 15000;
const byte waitingForEitherButton = 0;
const byte waitingForButton2 = 1;
const byte waitingForButton1 = 2;
const byte bothButtonsPressed = 3;
byte currentState = waitingForEitherButton;
void setup()
{
Serial.begin(115200);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
Serial.println("Waiting for a button press");
}
void loop()
{
currentMillis = millis();
switch (currentState)
{
case waitingForEitherButton:
if (digitalRead(buttonPin1) == LOW)
{
currentState = waitingForButton2;
waitStart = currentMillis;
Serial.println("Waiting for button 2");
}
if (digitalRead(buttonPin2) == LOW)
{
currentState = waitingForButton1;
waitStart = currentMillis;
Serial.println("Waiting for button 1");
}
break;
//
case waitingForButton2:
if (currentMillis - waitStart >= period)
{
currentState = waitingForEitherButton;
Serial.println("Waiting for either button");
}
if (digitalRead(buttonPin2) == LOW)
{
currentState = bothButtonsPressed;
}
break;
//
case waitingForButton1:
if (currentMillis - waitStart >= period)
{
currentState = waitingForEitherButton;
Serial.println("Waiting for either button");
}
if (digitalRead(buttonPin1) == LOW)
{
currentState = bothButtonsPressed;
}
break;
//
case bothButtonsPressed:
Serial.println("Both buttons pressed in time");
delay(2000); //naughty, but easy
Serial.println("Waiting for either button");
currentState = waitingForEitherButton;
break;
}
}
The program uses switch/case to move between various states and only executes the code for the current state. It uses millis() for timing so that code execution is not blocked apart from when both buttons have been pressed. It should really detect when buttons become pressed rather than when they are pressed and I fudged this by using delay() to avoid the second button press being detected as the first button press next time round. The program also wastes space by having the same constant text printed in more than one place, which is not good practice.
Look at how the program works in general then improve upon it
DO NOT take it as an example of good or efficient programming.
To try the program you need to put the pin numbers of your inputs into the variable initialisations instead of mine and wire the switches to take the inputs LOW when the buttons are pressed.