Need help to make a latching switch.

I need help with the Arduino UNO Spaceship Interface project. Currently, I have to hold the button so the two red Led lights start blinking and the green Led goes off, but I want to make it so when I press the button once the red LEDs start blinking and when I press it again they stop and the green LED comes back on. Here is the code what do I change about it?

int switchState = 0;
int ledOff = LOW;
int ledOn = HIGH;
int greenLed = 3;
int redLed_1 = 4;
int redLed_2 = 5;
int button = 2;

void setup() {
pinMode(greenLed, OUTPUT);
pinMode(redLed_1, OUTPUT);
pinMode(redLed_2, OUTPUT);
pinMode(button, INPUT);
}

void loop() {
switchState = digitalRead(button);

if (switchState == ledOff)

{
digitalWrite(greenLed, ledOn); //green LED
digitalWrite(redLed_1, ledOff); //red LED
digitalWrite(redLed_2, ledOff); //red LED
}

else {
digitalWrite(greenLed, ledOff);
digitalWrite(redLed_1, ledOff);
digitalWrite(redLed_2, ledOn);
delay(250);
digitalWrite(redLed_1, ledOn);
digitalWrite(redLed_2, ledOff);
delay(250);
}
}

Edit: I no longer need help thanks to you_know.

Look at the state-change example that comes with the Arduino IDE.

You need to update your variable when the button changes from not-pressed to pressed rather than when it is pressed.

...R

Note that there is a sneaky problem with implementing a switch toggle function in microcontroller code.

You actually have to learn how to de-bounce the button - or any other form of mechanical switch - first.

And note that this is done in code, you do not need hardware to do it and code does it vastly more effectively.

If you go and read the forum instructions so that you can go back and modify your original post using the "More -> Modify" option below the right hand corner of your post, then we can discuss this in detail.

You mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output for that matter when you need to) from the IDE and click the icon. In fact, the IDE has a "copy for forum" link to put these markings on for you so you then just paste it here in a posting window.

Do not attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code", it can be quite garbled and is always more difficult to read.