Chaning the state of multiple LEDS with a button

Hey all. My first post!
Anyways. I have set up an LED Chaser with 9 LEDS. They go from left to right, and then back again.
I have also programmed the LEDS to start from the center and move out, then move back in to the center.
Is there a way I can use a button to toggle between these two states?

Yes

At simple ‘state machine’ could be used.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components. Posting images:

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Ok, so I attached a diagram I made in Fritzing. Its my first time using it, so please be gentle.

My question should have bee a bit clearer. It should have been “Can I switch between two sketches by a button press?”
I’ll try to post my sketches, but I’m not sure I’m doing it properly. I also know that my code isn’t very efficient. If anyone has any tips on making it better, please advise me!

int LED1 = 13;
int LED2 = 12;
int LED3 = 11;
int LED4 = 10;
int LED5 = 9;
int LED6 = 8;
int LED7 = 7;
int LED8 = 6;
int LED9 = 5;

void setup() {
  // put your setup code here, to run once:
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
pinMode (LED7, OUTPUT);
pinMode (LED8, OUTPUT);
pinMode (LED9, OUTPUT);
}


void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(LED1, HIGH);
delay(100);
digitalWrite(LED2, HIGH);
delay(100);
digitalWrite(LED3, HIGH);
delay(100);
digitalWrite(LED4, HIGH);
delay(100);
digitalWrite(LED5, HIGH);
delay(100);
digitalWrite(LED6, HIGH);
delay(100);
digitalWrite(LED7, HIGH);
delay(100);
digitalWrite(LED8, HIGH);
delay(100);
digitalWrite(LED9, HIGH);
delay(100);
digitalWrite(LED1, LOW);
delay(100);
digitalWrite(LED2, LOW);
delay(100);
digitalWrite(LED3, LOW);
delay(100);
digitalWrite(LED4, LOW);
delay(100);
digitalWrite(LED5, LOW);
delay(100);
digitalWrite(LED6, LOW);
delay(100);
digitalWrite(LED7, LOW);
delay(100);
digitalWrite(LED8, LOW);
delay(100);
digitalWrite(LED9, LOW);
delay(100);
digitalWrite(LED9, HIGH);
delay(100);
digitalWrite(LED8, HIGH);
delay(100);
digitalWrite(LED7, HIGH);
delay(100);
digitalWrite(LED6, HIGH);
delay(100);
digitalWrite(LED5, HIGH);
delay(100);
digitalWrite(LED4, HIGH);
delay(100);
digitalWrite(LED3, HIGH);
delay(100);
digitalWrite(LED2, HIGH);
delay(100);
digitalWrite(LED1, HIGH);
delay(100);
digitalWrite(LED9, LOW);
delay(100);
digitalWrite(LED8, LOW);
delay(100);
digitalWrite(LED7, LOW);
delay(100);
digitalWrite(LED6, LOW);
delay(100);
digitalWrite(LED5, LOW);
delay(100);
digitalWrite(LED4, LOW);
delay(100);
digitalWrite(LED3, LOW);
delay(100);
digitalWrite(LED2, LOW);
delay(100);
digitalWrite(LED1, LOW);
delay(100);
}

The second one

int LED1 = 13;
int LED2 = 12;
int LED3 = 11;
int LED4 = 10;
int LED5 = 9;
int LED6 = 8;
int LED7 = 7;
int LED8 = 6;
int LED9 = 5;

void setup() {
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
pinMode (LED7, OUTPUT);
pinMode (LED8, OUTPUT);
pinMode (LED9, OUTPUT);
}


void loop() {
  // center LED will fade to next LED on either side of it.
digitalWrite(LED5, HIGH);
delay(100);
digitalWrite(LED4,LED6, HIGH, HIGH);
delay(100);
digitalWrite(LED3, LED7, HIGH, HIGH);
delay(100);
digitalWrite(LED2, LED8, HIGH, HIGH);
delay(100);
digitalWrite(LED1, LED9, HIGH, HIGH);
delay(100);
}

What you do is run different sections of a single sketch depending of switch presses.

On a switch press you increment a counter.

The counter resets when a maximum value is reached.

Based on the value of the counter you run a certain section of code.

Using the construct ‘switch/case’ and variable ‘counter’ you make a ‘state machine’ to execute sections of code.

Review this:

Thanks for the reply! You are awesome