two button anti tie down

I wanna do a project. In this project, there are 2 buttons and 1 led. If You press one of buttons, led should not work. If You press one of buttons and press another one in 0.5 seconds, led can work. But If You press only one button or you press second one after 0.5 seconds, led should not work.

But In my codes, I press buttons and remove my hands from buttons back from buttons, led still works. Led should work only during pressing buttons time.

boolean waitingForSecondButton = false;
byte button1=8;
byte button2=9;
int currentButton1;
int previousButton1;
long firstButtonPressTime;
long currentButton2State;
long previousButton2State;
long secondButtonPressTime;
byte led=3;
void setup()
{
  Serial.begin(115200);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(3,OUTPUT);
}

void loop()
{
  
    currentButton1 = digitalRead(button1);
  if (currentButton1 == LOW && previousButton1 == HIGH)
  {
    firstButtonPressTime = millis();
    waitingForSecondButton = true;
  }
  previousButton1 = currentButton1;

  currentButton2State = digitalRead(button2);
  if (currentButton2State == LOW && previousButton2State == HIGH && waitingForSecondButton == true)
  {
    secondButtonPressTime = millis();
    waitingForSecondButton = false;
    if (secondButtonPressTime - firstButtonPressTime <= 500 && waitingForSecondButton == false)
    {
      digitalWrite(3,HIGH);
    delay(3000);
      digitalWrite(3,LOW);
    }
    
  }
  previousButton2State = currentButton2State;}

k0rkunc:
I wanna do a project. In this project, after pushing one button if you don't push second one in 0.5s Led shouldn't work.

And In this project, led should work while I keep pushing the buttons.

But In my codes, I have a problem. I'm press button and take my hand back, led still works.

I can understand the first part but I don't understand what you mean in the second and third parts.

For the first part you need something like this

prevButton1State = button1State;
button1State = digitalRead(button1Pin);
if (button1State == LOW and prevButton1State == HIGH) { // assumes LOW when button is pressed
   button1Time = millis();
}
prevButton2State = button2State;
button2State = digitalRead(button2Pin);
if (button2State == LOW and prevButton2State == HIGH) {
   button2Time = millis();
}
if (button2Time - button1Time < 500) {
   digitalWrite(ledPIn, HIGH);
}

...R

Robin2:
I can understand the first part but I don't understand what you mean in the second and third parts.

For the first part you need something like this

prevButton1State = button1State;

button1State = digitalRead(button1Pin);
if (button1State == LOW and prevButton1State == HIGH) { // assumes LOW when button is pressed
  button1Time = millis();
}
prevButton2State = button2State;
button2State = digitalRead(button2Pin);
if (button2State == LOW and prevButton2State == HIGH) {
  button2Time = millis();
}
if (button2Time - button1Time < 500) {
  digitalWrite(ledPIn, HIGH);
}




i cant understand u :((

...R

So... two buttons, one LED.
Press either button on its own, no effect
Press either button 1 then 2 or 2 then one within 500 ms and the LED comes on?

For how long?
Do you need to hold both buttons down, or will a quick press do?

k0rkunc:
i cant understand u :((

If that's meant to be a smart-*rse response to my Reply #1 then I wish you well with your problems, but don't expect any more hep from me.

If it is a genuine comment then please let me know what you don't understand and I will try to help.

...R

GreyArea:
So... two buttons, one LED.
Press either button on its own, no effect
Press either button 1 then 2 or 2 then one within 500 ms and the LED comes on?

For how long?
Do you need to hold both buttons down, or will a quick press do?

When button 1 or 2 is pressed, the LED will be active as long as the other button is pressed within 500ms.