Need Help with Enter Button!

Hey everyone! I am new to coding and arduino. I have been working on arduino code that uses inputs to make LEDs light up in binary (for school). I have finished the if statements, all I need now is to figure out how to make an enter button. I call the enter function void enter(), however, the LEDs light up when I press the button. Please help. I can give more information if needed.

Here is what my arduino looks like on tinkercad: Arduino - Album on Imgur

Thanks.

/*
Create an Arduino device with three Input Buttons and four LED output.

The four LED lights will be used to count from 0 up to 15.
That means it should be able to count from 0 to 1, 0 to 2, 0 to 6, etc.

Three buttons should work in the following way.
Button #1: The number of times you push this button will be the number that your LEDs will count to.
Button #2: Count button: When button two is pressed the LED lights will begin counting
Button #3: Reset button: When button three is pressed the LED lights will stop counting the Button #1 count will be reset to zero.
*/
int Lamp1 = 4;
int Lamp2 = 5;
int Lamp3 = 6;
int Lamp4 = 7;
int ButtonCount;// Count how many times button is pressed
int buttonState; // Stored the button as int buttonState
int buttonState2;
int buttonState3;
int lastButtonState;
int lastButtonState2;

void setup()
{
  Serial.begin(9600);
 pinMode(3,INPUT);// define the pin number 
 pinMode(8, INPUT);//Press to light up leds
}

void loop()
{
  //BUTTON STATES USED TO MAKE SURE THE BUTTON DOESNT REPEATEDLY SEND INFO WHEN PRESSED (LIKE A DEBOUNCE)
  buttonState2 = digitalRead(8);//Press to light up leds (enter button)  
  buttonState = digitalRead(3);//Press to count
  
  if(lastButtonState != buttonState){
  	if(buttonState==HIGH)// if the current state is HIGH then the button went from off to on:
  	{
    	ButtonCount=ButtonCount+1;//increment in i when button is pressed.
    	Serial.println(ButtonCount);
  	}
    //IF STATEMENTS

  }
    lastButtonState = buttonState;
  if (buttonState2==HIGH){
  enter();
  }
}


void enter()
{
    if (ButtonCount==1)
    {
     digitalWrite(Lamp1, LOW);
     digitalWrite(Lamp2, LOW);
     digitalWrite(Lamp3, LOW);
     digitalWrite(Lamp4, HIGH);
    }
        if (ButtonCount==2)
    {
     digitalWrite(Lamp1, LOW);
     digitalWrite(Lamp2, LOW);
     digitalWrite(Lamp3, HIGH);
     digitalWrite(Lamp4, LOW);
    }
            if (ButtonCount==3)
    {
     digitalWrite(Lamp1, LOW);
     digitalWrite(Lamp2, LOW);
     digitalWrite(Lamp3, HIGH);
     digitalWrite(Lamp4, HIGH);
    }
            if (ButtonCount==4)
    {
     digitalWrite(Lamp1, LOW);
     digitalWrite(Lamp2, HIGH);
     digitalWrite(Lamp3, LOW);
     digitalWrite(Lamp4, LOW);
    }    
}

how did you wire the buttons?

why do you have this

  if (lastButtonState != buttonState) {
    if (buttonState == HIGH) // if the current state is HIGH then the button went from off to on:
    {
      ButtonCount = ButtonCount + 1; //increment in i when button is pressed.
      Serial.println(ButtonCount);
    }

and not something similar for buttonState2?

I wired the buttons like this: arduino

Sorry, I forgot about the second button state, I am new to coding. Is my way of calling the function inside of the loop the reason it loops?

The button on the left does not have a resistor, why?

you call the Enter function as long as the condition (buttonState2==HIGH) is true ➜ so whilst the button is pressed, not just once when it is being pressed (upon the transition)

(button can bounce too, so this needs to be taken into account as well)

you should read a tutorial on push buttons (and use INPUT_PULLUP to make your life easy)

It is a reset button, this resets the board.

I am not sure what you mean by the button can bounce. Could you please explain it? Thank you.

also read this

➜ "Keep in mind that Just because you have nothing at all connected to an input pin doesn’t mean it is a logical zero"

Look at this. I simple fix is to put a short delay after state change is detected to prevent it from being re-detected for no reason.

Thank you, I will take a look at these.

Figured out the issue. There was a circuit error, and a few code errors. Thanks all!