2 buttons 1 LED

Hello everyone, im sure there is a simple way to do this but im still fairly new with coding the Arduino (UNO). Im trying to make a simple circuit with 2 push buttons and a LED. All i want is to have is one button that turns the LED on an keeps it on untill the second switch is pushed 4 times and will turn it off. I managed to make the LED come on with the first button using the standard Arduino example but im having difficulty getting this to work, any help would be amazing.

Its kindof hard to explain without and code

Is button pressed AND buttonEnabled?
numPresses ++;
buttonEnabled = false;
lastPressed = millis();
else
buttonEnabled = true;

If millis() - lastPressed > 1000 //1 second
numPresses = 0;

delay(1);

Thank you but I haven't got anything written yet, surely I need to declare 2 separate buttons though? If there already example code that exsists so I could use that?

Download the arduino IDE, look under File->Examples->Blink

Now that you basically have everything you need, get started.
Just remember, we are not here to program it for you, just help you get on your way.

You may find this example to be useful.

I am feeling generous

const byte ledPin = 13;
const byte buttonPin1 = A1;
const byte buttonPin2 = A2;
boolean ledIsOn = false;
byte previousButtonState1 = HIGH;
byte currentButtonState1 = HIGH;
byte previousButtonState2 = HIGH;
byte currentButtonState2 = HIGH;
byte buttonCount = 0;
void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  digitalWrite(ledPin, HIGH);
}

void loop()
{
  if (!ledIsOn)  //LED currently off
  {
    currentButtonState1 = digitalRead(buttonPin1);
    if (currentButtonState1 != previousButtonState1 && currentButtonState1 == LOW)  //button 1 has become pressed
    {
      digitalWrite(ledPin, LOW);  //turn on the LED
      ledIsOn = true;
      buttonCount = 0;
    }
    previousButtonState1 = currentButtonState1;
  }
  else        //the LED is on
  {
    currentButtonState2 = digitalRead(buttonPin2);
    if (currentButtonState2 != previousButtonState2 && currentButtonState2 == LOW)  //button 2 has decome pressed
    {
      buttonCount++;
      Serial.println(buttonCount);  //count the button press
    }
    if (buttonCount == 4)  
    {
      digitalWrite(ledPin, HIGH);
      buttonCount = 0;
      ledIsOn = false;
    }
    previousButtonState2 = currentButtonState2;
  }
}

But your code does not account for button bouncing...

The OP has obviously found it difficult enough already without introducing extra complications. As it is I am half expecting it not to work for him because he has his buttons and/or LEDs wired differently than I do but we can cross further bridges when we come to them.

In any case, button1 does not need debouncing because it is a latch. Feel free to post a complete solution with debouncing included.

#define BUTTON1 2
#define BUTTON2 3
#define LED 13

unsigned long lastPressed = 0;
boolean buttonEnable = true;
boolean ledStatus = false;
byte numPresses = 0;

void setup()
{
  pinMode(BUTTON1, INPUT);
  pinMode(BUTTON2, INPUT);
  pinMode(LED, OUTPUT);
}

void loop()
{
  if(digitalRead(BUTTON1))
  {
    ledStatus = true;
    digitalWrite(LED, HIGH); //you said you only want this button to turn it on
  }
  if(digitalReaD(BUTTON2) && buttonEnable && ledStatus)
  {
    buttonEnable = false;
    numPresses++;
    lastPressed = millis();
  }
  //10 millisecond delay between presses to prevent bouncing events
  if(!buttonEnable && abs(millis() - lastPressed) > 10) //I put the absolute value to prevent a rare error of millis() overflow and the button never re-enabling itself. But this would only happen after ~50 days of continuous on-time and a VERY well timed button press, but still, its a potential error!
  {
    buttonEnable = true;
  }
  else if(buttonEnable && abs(millis() - lastPressed) > 3000) //if you dont press the button in 3 seconds of the last press, the counter resets
  {
    numPresses = 0;
  }
  if(numPresses >= 4)
  {
    numPresses = 0;
    ledStatus = false; //you said you want it to turn off after 4 presses
    digitalWrite(LED, LOW);
  }
  delay(1);
}

I put the absolute value to prevent a rare error of millis() overflow and the button never re-enabling itself.

My understanding is there is no need for the abs() because by subtracting the previous time from the current time and using unsigned longs for the timing variables the right answer is returned even after millis() rolls over to zero.

I put the absolute value to prevent a rare error of millis() overflow and the button never re-enabling itself.

I'm not sure how abs() would change anything anyway. The millis timer never counts into the negative so the abs() value should always equal the millis() value. Please enlighten me if i am missing something obvious.

The abs() in the code is intended to deal with the situation where millis() has rolled over to zero and started its count again but lastPressed was saved before the rollover.

However, it is not needed. See millis() rollover

Got me there, forgot I was working with unsigned