Adding a push button into an already existing sketch

I'm new to the Arduino community and programming in general. I have an existing sketch that was written by Kurtsmaze. I altered it a little to fit my needs. what the sketch is is 5 lights fading in and out randomly like Christmas lights. What I want to do is add a button so when pressed all 5 lights stay on steady until the button is pressed agin to go back to the fade loop. any help would be great thank you

// christmas tree lights 

#define NR_OF_LIGHTS 6
int pins[NR_OF_LIGHTS] = { 3, 5, 6, 9, 10, }; 

int values[NR_OF_LIGHTS];
int steps[NR_OF_LIGHTS];

#define NR_OF_FADESTEPS 4
int fadesteps[NR_OF_FADESTEPS] = { 192, 128, 64, 0 }; 
int fade_delay = 30; // millisec
int fade_cycles = 1000;



int effect = 1;

int randomlights[NR_OF_LIGHTS];
bool chosenlights[NR_OF_LIGHTS];


/**
 *
 */
void setup() { 
  randomSeed(analogRead(0));
  for (int i = 0; i < NR_OF_LIGHTS; i++) {
    values[i] = (int)random(230) + 13; // start values between 'max min' and 'min max'
    steps[i] = (int)random(4) + 1; // steps between 1 and 4
  }
} 

/**
 *
 */
void loop() { 

  for (int j = 0; j < fade_cycles; j++) {
    for (int i = 0; i < NR_OF_LIGHTS; i++) {
      fadingLight(i);  
    }
    delay(fade_delay);
  }

  if (effect == 1) {

    effect = 2;
  }
  else if (effect == 2) {
    runningLight(0);
    effect = 3;
  }
  else if (effect == 3) {
    runningLight(255);
    effect = 1;
  }
} 

/**
 *
 */
void fadingLight(int i) {
  
  int minvalue = (NR_OF_FADESTEPS * abs(steps[i])) + 1;
  int maxvalue = 255 - minvalue;

  int fs = NR_OF_FADESTEPS;
  for (int j = 0; fs > 0; fs--, j++) {
    if (values[i] > fadesteps[j]) {
        break;
    }
  }
  values[i] += fs * steps[i];
  
  if (values[i] > maxvalue  ||  values[i] < minvalue) {
      steps[i] *= -1;
  }
  
  analogWrite(pins[i], values[i]);
}

/**
 *
 */
void setAllLights(int value) {
  for (int i = 0; i < NR_OF_LIGHTS; i++) {
    analogWrite(pins[i], value);
  }
}

/**
 *
 */


/**
 *
 */
void runningLight(int startvalue) {
  setAllLights(startvalue);
  for (int j = 0; j < 2; j++) {
    randomize();
    for (int i = 0; i < NR_OF_LIGHTS; i++) {
      analogWrite(pins[randomlights[i]], 255 - startvalue);
      delay(200);
      analogWrite(pins[randomlights[i]], startvalue);
    }
  }
}


/**
 *
 */
void randomize() {
  for (int i = 0; i < NR_OF_LIGHTS; i++) {
    chosenlights[i] = false;
  }
  //first one always ok
  int r = (int)random(NR_OF_LIGHTS);
  randomlights[0] = r;
  chosenlights[r] = true;
  //next 4
  for (int i = 1; i < 5; i++) {
    while (true) {
      r = (int)random(NR_OF_LIGHTS);
      if (chosenlights[r] == false) {
        break;
      }
    }
    randomlights[i] = r;
    chosenlights[r] = true;
  }
  //last one  
  for (int i = 0; i < NR_OF_LIGHTS; i++) {
    if (chosenlights[i] == false) {
      randomlights[5] = i;
      break;
    }
  }
}

What I want to do is add a button so when pressed all 5 lights stay on steady until the button is pressed agin to go back to the fade loop. any help would be great thank you

Well, you have our permission. What is then problem?

Perhaps you should take a look at the state change detection example. Increment a value each time the switch becomes pressed.

When the counter is even, do one thing. When it is odd, do the other. The modulo operator (%) with an operand of 2 will tell you odd or even.

something like this (untested)

// christmas tree lights 

#define NR_OF_LIGHTS 6
#define NR_OF_FADESTEPS 4

int pins[NR_OF_LIGHTS] = { 3, 5, 6, 9, 10, }; 
int values[NR_OF_LIGHTS];
int steps[NR_OF_LIGHTS];
int fadesteps[NR_OF_FADESTEPS] = { 192, 128, 64, 0 }; 
int fade_delay = 30; // millisec
int fade_cycles = 1000;
int effect = 1;
int randomlights[NR_OF_LIGHTS];
bool chosenlights[NR_OF_LIGHTS];
//
byte buttonPin = 4;
boolean state = true;
byte lastPressed;

void setup() 
{ 
  pinMode(buttonPin, INPUT_PULLUP);
  randomSeed(analogRead(0));
  for (int i = 0; i < NR_OF_LIGHTS; i++) 
  {
    values[i] = (int)random(230) + 13; // start values between 'max min' and 'min max'
    steps[i] = (int)random(4) + 1; // steps between 1 and 4
  }
} 

void loop() 
{ 
  int pressed = digitalRead(buttonPin);
  if (pressed == LOW && lastPressed == HIGH)
  {
    state = !state;
  }
  if (state)
  {
    for (int j = 0; j < fade_cycles; j++) {
      for (int i = 0; i < NR_OF_LIGHTS; i++) {
        fadingLight(i);  
      }
      delay(fade_delay);
    }
    if (effect == 1) 
    {
      effect = 2;
    }
    else if (effect == 2) 
    {
      runningLight(0);
      effect = 3;
    }
    else if (effect == 3) 
    {
      runningLight(255);
      effect = 1;
    }
  }
  else
  {
    for (byte i = 0; i < NR_OF_LIGHTS; i++)
    {
      digitalWrite(pins[i], HIGH);
    }
  }
  lastPressed = pressed;
} 

void fadingLight(int i) 
{
  int minvalue = (NR_OF_FADESTEPS * abs(steps[i])) + 1;
  int maxvalue = 255 - minvalue;

  int fs = NR_OF_FADESTEPS;
  for (int j = 0; fs > 0; fs--, j++) {
    if (values[i] > fadesteps[j]) {
      break;
    }
  }
  values[i] += fs * steps[i];

  if (values[i] > maxvalue  ||  values[i] < minvalue) {
    steps[i] *= -1;
  }

  analogWrite(pins[i], values[i]);
}

void setAllLights(int value) {
  for (int i = 0; i < NR_OF_LIGHTS; i++) {
    analogWrite(pins[i], value);
  }
}

void runningLight(int startvalue) {
  setAllLights(startvalue);
  for (int j = 0; j < 2; j++) {
    randomize();
    for (int i = 0; i < NR_OF_LIGHTS; i++) {
      analogWrite(pins[randomlights[i]], 255 - startvalue);
      delay(200);
      analogWrite(pins[randomlights[i]], startvalue);
    }
  }
}


/**
 *
 */
void randomize() 
{
  for (int i = 0; i < NR_OF_LIGHTS; i++) 
  {
    chosenlights[i] = false;
  }
  //first one always ok
  int r = (int)random(NR_OF_LIGHTS);
  randomlights[0] = r;
  chosenlights[r] = true;
  //next 4
  for (int i = 1; i < 5; i++) 
  {
    while (true) {
      r = (int)random(NR_OF_LIGHTS);
      if (chosenlights[r] == false) 
      {
        break;
      }
    }
    randomlights[i] = r;
    chosenlights[r] = true;
  }
  //last one  
  for (int i = 0; i < NR_OF_LIGHTS; i++) 
  {
    if (chosenlights[i] == false) 
    {
      randomlights[5] = i;
      break;
    }
  }
}

Thank you, I'm going to try it a little later today when i have time. see what i can come up with

So i did some more research and her is what i found on The Mozmonkey Blog by Jeremy Gillick.

The problem is in that 30 millisecond delay. This stops your entire program for 30 milliseconds. If you want a slower fade, you have to set it to a higher value and a longer pause. If you’re fading multiple LEDs at different rates, the arduino ends up being paused more time than it’s processing. Which means it’s hard to do anything besides fade a bunch of LEDs.

cllupien:
So i did some more research and her is what i found on The Mozmonkey Blog by Jeremy Gillick.

The problem is in that 30 millisecond delay. This stops your entire program for 30 milliseconds. If you want a slower fade, you have to set it to a higher value and a longer pause. If you’re fading multiple LEDs at different rates, the arduino ends up being paused more time than it’s processing. Which means it’s hard to do anything besides fade a bunch of LEDs.

Then don't use delay. Instead, look at the 'Blink without delay' example in either the examples page of this site or the IDE.
Read, understand and embrace the principle it uses.