Im new to this and stuck..... can anyone help me please. ?

hi, im new to the forum and this is my 1st post, my names Matt and im from Essex in the UK, im sure this will be one of many posts as i start my new venture into programming.

ok so after a few days of reading and copying code i decided to try and write something my self,

my 1st program was a basic led program, with a switch,
1x led
1x switch

but when i wire everything up my red led blinks, and its ment to be solid, then after 4 presses of the button it should go off.

here is my code and ive attached a photo of my wiring from the mega 2560 to the breadboard.

int ledRed1 = 2; // red LED's var name
int ledYellow1 = 3; // yellow LED's var name
int ledGreen1 = 4; // green LED's var name
int ledSwitch = 10; //  button for switching LED's
int redTimer = 1000; // set red LED's blinking time to 1000miliseconds
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);  // initialize serial communication
pinMode(ledRed1, OUTPUT); // initalize red led 1 as output
pinMode(ledSwitch, INPUT); // initalise button as input
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(ledRed1, HIGH); // turn led on
delay(redTimer); // wait for timer to finish
digitalWrite(ledRed1, LOW); // turn led off
delay(redTimer); // wait for timer to finish

buttonState = digitalRead(ledSwitch); // read which input the button is stored on
if (buttonState != lastButtonState) { // compare the buttonState to its previous state
    
    if (buttonState == HIGH) { // if the state has changed, increment the counter & if the current state is HIGH then the button went from off to on:
       buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else {
      Serial.println("off");       // if the current state is LOW then the button went from on to off:
    }
  }
  lastButtonState = buttonState;   // save the current state as the last state, for next time through the loop

 
  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledRed1, HIGH);
  } else {
   digitalWrite(ledRed1, LOW);
  }
  


}

i must admit the switching part is not my own code, but i have written it rather then copying it and pasting it. so maybe this is where ive gone wrong.

hopefully someone can explan to me where ive gone wrone. ?

pinMode(ledSwitch, INPUT); // initalise button as input

I don't see a resistor wired with that switch. Using INPUT_PULLUP makes switch so much easier to wire. One leg to the digital pin. One leg to ground. Then, LOW means pressed and HIGH means released. Otherwise, without an external resistor, you have a floating pin, and they are not good things.

Welcome to the forum, and congratulations for using code tags and a photo in your first posting.

The wiring of some 4 leg button switches can be confusing because two of the four legs are always connected to each other. If you wire diagonally across the button then it will always be open when not pressed, and it will close the circuit when pressed. Wiring should be from the INPUT_PULLUP pin, diagonally across the switch to ground.