Waiting for a second input within a timeframe

Hi
I'm pretty new to Arduino and I'm trying to create my first project.
It's going well but I need some help with an specific function.
The idea for this project is that there are 2 momentary switches.

  • Pressing button1 will turn on led1
  • Pressing button2 will turn on led2
  • If they are both pressed within 1 second, it should blink both.

Any idea on how could I make it "wait" for the second button?

Thanks

void loop() {
// Acao caso o toque seja acionado
unsigned long currentMillis = millis();

if (digitalRead(button1) == LOW {

// How can I wait for 1 second here?

if (digitalRead(button2) == LOW {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
delay(1000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
delay(500);
}
else
digitalWrite(LED1, HIGH);
delay(1000);

Thanks

Any idea on how could I make it “wait” for the second button?

I guarantee that you do NOT want to do that.

What you should do is look at the State Change Detection example, and learn how to detect that a switch HAS BECOME pressed or HAS BECOME released, rather than IS pressed or IS released.

When a switch BECOMES pressed, record the time, using millis().

If both times (when the first switch became pressed and when the second switch became pressed) are close enough, do the appropriate thing.

You’ll need to determine when the clear the time variables.