Get my program to go to the next loop no matter when my pushbutton is pressed?

int pin2 = 2; int pin3 = 3; int pin4 = 4; int pin5 = 5; int pin6 = 6; int pin7 = 7; int pin8 = 8; int pin9 = 9; int pin10 = 10; int pin11 = 11; int pin12 = 12; int timer = 35; int switchPin = 13; // switch connected to pin 1

int val; // variable for reading pin status int val2; // variable for reading the delay/bounce int buttonState; // variable to hold the button state int lightMode = 0; // Light on or off?

void setup(){ pinMode(switchPin, INPUT); // set the switch pin as input

pinMode(pin2, OUTPUT); pinMode(pin3, OUTPUT); pinMode(pin4, OUTPUT); pinMode(pin5, OUTPUT); pinMode(pin6, OUTPUT); pinMode(pin7, OUTPUT); pinMode(pin8, OUTPUT); pinMode(pin9, OUTPUT); pinMode(pin10, OUTPUT); pinMode(pin11, OUTPUT); pinMode(pin12, OUTPUT);

Serial.begin(9600); // set up serial communication at 9600 baud buttonState = digitalRead(switchPin); // read the intial state }

void loop() { val = digitalRead(switchPin); // read input value and store it in val delay(10); val2 = digitalRead(switchPin); // read the input again if (val == val2) { if (val != buttonState) { // the button state has changed if (val == LOW) { // check if the button is pressed if (lightMode == 0) { // light is off lightMode = 1; // light is on } else { if (lightMode == 1) { lightMode = 2; } else { if (lightMode == 2) { lightMode = 3; } else { if (lightMode == 3) { lightMode = 4; } else { if (lightMode == 4) { lightMode = 5; } else { if (lightMode == 5) { lightMode = 6; } else { if (lightMode == 6) { lightMode = 7; } else { if (lightMode == 7) { lightMode = 8; } else { if (lightMode == 8) { lightMode = 0; } } } } } } } } } } buttonState = val; // save the new state in our variable }

if (lightMode == 0) { // all-off digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); digitalWrite(pin5, LOW); digitalWrite(pin6, LOW); digitalWrite(pin7, LOW); digitalWrite(pin8, LOW); digitalWrite(pin9, LOW); digitalWrite(pin10, LOW); digitalWrite(pin11, LOW); digitalWrite(pin12, LOW);

}

if (lightMode == 1) { // all-on digitalWrite(pin2, HIGH); digitalWrite(pin3, HIGH); digitalWrite(pin4, HIGH); digitalWrite(pin5, HIGH); digitalWrite(pin6, HIGH); digitalWrite(pin7, HIGH); digitalWrite(pin8, HIGH); digitalWrite(pin9, HIGH); digitalWrite(pin10, HIGH); digitalWrite(pin11, HIGH); digitalWrite(pin12, HIGH);

}

if (lightMode == 2) { digitalWrite(pin2, HIGH); digitalWrite(pin3, HIGH); digitalWrite(pin4, HIGH); digitalWrite(pin5, HIGH); digitalWrite(pin6, HIGH); digitalWrite(pin7, HIGH); digitalWrite(pin8, HIGH); digitalWrite(pin9, HIGH); digitalWrite(pin10, HIGH); digitalWrite(pin11, HIGH); digitalWrite(pin12, HIGH);

delay(1000);

digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); digitalWrite(pin5, LOW); digitalWrite(pin6, LOW); digitalWrite(pin7, LOW); digitalWrite(pin8, LOW); digitalWrite(pin9, LOW); digitalWrite(pin10, LOW); digitalWrite(pin11, LOW); digitalWrite(pin12, LOW);

delay(500);

}

if (lightMode == 3) { digitalWrite(pin2, HIGH); digitalWrite(pin3, HIGH); digitalWrite(pin4, HIGH); digitalWrite(pin5, HIGH); digitalWrite(pin6, HIGH); digitalWrite(pin7, HIGH); digitalWrite(pin8, HIGH); digitalWrite(pin9, HIGH); digitalWrite(pin10, HIGH); digitalWrite(pin11, HIGH); digitalWrite(pin12, HIGH);

delay(200);

digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, LOW); digitalWrite(pin5, LOW); digitalWrite(pin6, LOW); digitalWrite(pin7, LOW); digitalWrite(pin8, LOW); digitalWrite(pin9, LOW); digitalWrite(pin10, LOW); digitalWrite(pin11, LOW); digitalWrite(pin12, LOW);

delay(200);

}

if (lightMode == 4) { digitalWrite(pin11, LOW); digitalWrite(pin12, LOW); digitalWrite(pin2, HIGH); digitalWrite(pin3, HIGH);

delay(500);

digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, HIGH);

delay(500);

digitalWrite(pin4, LOW); digitalWrite(pin5, HIGH); digitalWrite(pin6, HIGH);

delay(500);

digitalWrite(pin5, LOW); digitalWrite(pin6, LOW); digitalWrite(pin7, HIGH);

delay(500);

digitalWrite(pin7, LOW); digitalWrite(pin8, HIGH); digitalWrite(pin9, HIGH);

delay(500);

digitalWrite(pin8, LOW); digitalWrite(pin9, LOW); digitalWrite(pin10, HIGH);

delay(500);

digitalWrite(pin10, LOW); digitalWrite(pin11, HIGH); digitalWrite(pin12, HIGH);

delay(500);

}

if (lightMode == 5) { digitalWrite(pin11, LOW); digitalWrite(pin12, LOW); digitalWrite(pin2, HIGH); digitalWrite(pin3, HIGH);

delay(50);

digitalWrite(pin2, LOW); digitalWrite(pin3, LOW); digitalWrite(pin4, HIGH);

delay(50);

digitalWrite(pin4, LOW); digitalWrite(pin5, HIGH); digitalWrite(pin6, HIGH);

delay(50);

digitalWrite(pin5, LOW); digitalWrite(pin6, LOW); digitalWrite(pin7, HIGH);

delay(50);

digitalWrite(pin7, LOW); digitalWrite(pin8, HIGH); digitalWrite(pin9, HIGH);

delay(50);

digitalWrite(pin8, LOW); digitalWrite(pin9, LOW); digitalWrite(pin10, HIGH);

delay(50);

digitalWrite(pin10, LOW); digitalWrite(pin11, HIGH); digitalWrite(pin12, HIGH);

delay(50);

}

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int pin11 = 11;
int pin12 = 12;

When you start numbering variables, that is a sure sign that you need arrays.

if (lightMode == 0) {       // light is off
         lightMode = 1;               // light is on
      } else {
     if (lightMode == 1) {
         lightMode = 2;
     } else {
     if (lightMode == 2) {
         lightMode = 3;
     } else {
     if (lightMode == 3) {
         lightMode = 4;
     } else {
       if (lightMode == 4) {
           lightMode = 5;
     } else {
       if (lightMode == 5)  {
           lightMode = 6;
     } else {
       if (lightMode == 6)  {
           lightMode = 7;
     } else {
       if (lightMode == 7)  {
           lightMode = 8;
     } else {
       if (lightMode == 8) {
           lightMode = 0;
     }

Unless lightMode is 8, lightMode is incremented by 1. This mess should be:

  lightMode++;
  if(lightMode > 8)
    lightMode = 0;

How IS your switch wired? Using the interval pullup resistor, you coul connect one leg to ground and one leg to the digital pin. No other wiring is nearly as simple.

There are stickies at the top of the forum. Read them before you embarrass yourself incorrectly posting code. I KNOW your code does not look like that.