How switch between 2 different codes?

Ok I now have a complete code with no errors when i verify it I uploaded it to my board and it does not work.. I have a 10kOhm Resistor running from pin 7 to ground and a switch running from pin 7 to +5v and I am pretty darn sure that is how that is supposed to be.. but when the switch is flipped or not flipped it only runs the fader code...
here is the finished code with no errors.. any idea why this is not working... oh and the two codes work fine by themselves

int rpin = 9;
int gpin = 10;
int bpin = 11;
int potpin = 2;
int readPin = 7;
float h;                    
int h_int;                   
int r = 0, g = 0, b = 0;           

int val = 0;                   

void h2rgb(float h, int& R, int& G, int& B); 

void fadeUp(int pin, int d = 10)
{
  int i;
  for (i = 255; i >= 0; i--)
  {
    analogWrite(pin, i);
    delay(d);
  }
}


void fadeDown(int pin, int d = 20)
{
  int i;
  for (i = 0; i <= 255; i++)
  {
    analogWrite(pin, i);
    delay(d);
  }
}

void setup()
{
  Serial.begin(9600);
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);
  pinMode(readPin, INPUT);
  analogWrite(rpin, 255);
  analogWrite(gpin, 255);
  analogWrite(bpin, 255);
}

boolean wayOne = true;

void loop()
{
   if(digitalRead(7) == HIGH)
   {
      wayOne = !wayOne;
   }

   if(wayOne)
      loop1();
   else
      loop2();
} 

void loop1()
{
  fadeUp(bpin);
  fadeUp(gpin);
  fadeDown(bpin);
  fadeUp(rpin);
  fadeDown(gpin);
  fadeUp(bpin);
  fadeDown(rpin);
}


void loop2()                     
{
  val = analogRead(potpin);    
  h = ((float)val)/1024;       
  h_int = (int) 360*h;         

  h2rgb(h,r,g,b);              

  Serial.print("POT value: ");
  Serial.print(val);           
  Serial.print(" = Hue of ");
  Serial.print(h_int);         
  Serial.print(" degrees. RGB values: ");
  Serial.print(r);             
  Serial.print(" ");
  Serial.print(g);            
  Serial.print(" ");
  Serial.println(b);           

  analogWrite(rpin, r);        
  analogWrite(gpin, g);        
  analogWrite(bpin, b);        

}

void h2rgb(float h, int& R, int& G, int& B) {

 
  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;      
    var_i = int( var_h ) ;            
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * 255;                  
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
  
  
}

Add a Serial.print() statement in the if(digitalRead(7) == HIGH) block, so you know whether the button is being read correctly. If not, it's a hardware problem.

What kind of switch is it?

its a N/O button switch, it worked just fine when i tested it with the example code "button" .. the final switch will be a toggle switch
so do this to the code

void loop()
{
   if(digitalRead(7) == HIGH)
   Serial.print() 

   {
      wayOne = !wayOne;
   }

   if(wayOne)
      loop1();
   else
      loop2();
}

EDIT: got this error when i verified it "error: no matching function for call to 'HardwareSerial::print()'"

Add a Serial.print() statement in the if(digitalRead(7) == HIGH) block

   if(digitalRead(7) == HIGH)
   {
      Serial.print([glow]"Switch was pressed"[/glow])[glow];[/glow]
      wayOne = !wayOne;
   }

it still does the same thing i even replaced the switch with a straight piece of wire and nothing...
and I dont know where it was supposed to say "switch was pressed" but it didnt anywhere.. with the switch or the piece of wire

EDIT: I just tried changing it to a different pin instead of 7 i used 4 and that didnt work either

ok i just tested my setup with the example sketch "button" and it works fine.. i subbed in my codes just like you told me too and i got no error messages but when i uploaded it to the board it does not work... If ANYONE has a rgb led and an arduino sitting around please try this for yourself and see if you can figure it out all i want this thing to do is when a switch is flipped up it will just cycle through all the colors and whe the switch is flipped down you can control the colors with one potentiometer i have the codes to do one or the other but putting them together has been a complete nightmare. here are both of the codes if anyone wants to try this (i am only posting code because i am useing a different code for the auto color cycle) i am tempted to just get two arduinos and switch between them but i know this is doable i just cant figure the code out, so far everyone has been a big help i guess i am just an idiot.

int rpin = 9;
int gpin = 10;
int bpin = 11;


void fadeUp(int pin, int d = 10)
{
  int i;
  for (i = 255; i >= 0; i--)
  {
    analogWrite(pin, i);
    delay(d);
  }
}


void fadeDown(int pin, int d = 20)
{
  int i;
  for (i = 0; i <= 255; i++)
  {
    analogWrite(pin, i);
    delay(d);
  }
}


void setup()
{
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);

  analogWrite(rpin, 255);
  analogWrite(gpin, 255);
  analogWrite(bpin, 255);

}


void loop()
{
  fadeUp(bpin);
  fadeUp(gpin);
  fadeDown(bpin);
  fadeUp(rpin);
  fadeDown(gpin);
  fadeUp(bpin);
  fadeDown(rpin);
}
int potpin = 2;              // POT connected to digital pin 2 - pos/neg are left and right connections on POT
int rpin = 9;                // Red
int gpin = 10;               // Green
int bpin = 11;               // Blue
float h;                     // Hue range
int h_int;                   // Hue color
int r = 0, g = 0, b = 0;           // Default RGB values

int val = 0;                   // Set POT value to default 0

void h2rgb(float h, int& R, int& G, int& B); // Instantiate h2rgb and it's variables  a.k.a  Hue to RGB

void setup()                    // Run once, when the sketch starts
{
  Serial.begin(9600);          // Begin the output of data to serial
}


void loop()                     // Run over and over again
{
  val = analogRead(potpin);    // Read the pin and display the value
  h = ((float)val)/1024;       // Get the range. pot value / 1024
  h_int = (int) 360*h;         // Get the color hue by multiplying by 360

  h2rgb(h,r,g,b);              // Call the h2rgb function passing it the hue value

  Serial.print("POT value: ");
  Serial.print(val);           // Pot value
  Serial.print(" = Hue of ");
  Serial.print(h_int);         // Color Hue value
  Serial.print(" degrees. RGB values: ");
  Serial.print(r);             // Red value
  Serial.print(" ");
  Serial.print(g);             // Green value
  Serial.print(" ");
  Serial.println(b);           // Blue value

  analogWrite(rpin, r);        // Changes red led
  analogWrite(gpin, g);        // Changes green led
  analogWrite(bpin, b);        // Changes blue led

}

void h2rgb(float h, int& R, int& G, int& B) {

  // Used HSV --> RGB function
  // HSV - Hue, Saturation, Value
  // RGB - Red, Green, Blue - example (255,255,255)
  // Function below does a bunch of math to convert HSV values to RGB
  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
}

ok i just tested my setup with the example sketch "button" and it works fine..

So, change the sample sketch to print, on the Serial Monitor (there is a button with that name on the Arduino IDE, next to the Upload button), "Button was pressed", using Serial.print(), every time the button is pressed.

When that works, change the code to add a boolean variable, initially set to false. Toggle it every time the button is pressed. Then, print the state ("state = false" or "state = true").

Then, replace the code in loop() that prints the button state to calling two functions that print something.

Learn and understand what you are doing, in small steps. Here are 3 small steps. If you have trouble with any one, post the small sketch that is not doing what you want, and we'll help you fix it.

ok I will give that a shot when i get off work tonight.

ok useing the state change detection i am actually getting somewhere i can make it so that when powered up it does nothing and when i push the button it starts auto cycling throuhg the colors but it wont switch back i have to push the reset button on the arduino (which i am fine with) but when i put the code for the control of the colors with a single pot it throws up an error it has a problem with this part of the code

 analogWrite(bpin, b);        // Changes blue led

}

[glow]void h2rgb(float h, int& R, int& G, int& B)[/glow] { 

  // Used HSV --> RGB function

any suggestions?
it says "function definition not allowed here after "{" token"...
or it may be "}" token

EDIT: I can make it do things on startup by changing what is in loop1() but when i start the auto color cycling sketch it wont switch back.. but if i take out the cycling code it will switch an led on pin 13 on when i push the button and off when i push the button again

any suggestions?

Show us the rest of the code - the problem does not lie with the bit you posted.

Well I went to past the code back in and noticed an extra set of these "{}" i took those out pasted the codes back in and hooray it works when i turn it on i can control the led with the potentiometer, then i push the button and it auto cycles then i can change it back but i have to push the reset button...
Thanks for all of the help!!

and it auto cycles then i can change it back but i have to push the reset button...

This means that you are not reading the button state in the function that loops. You can either read the button state in that function, or stop the looping. Since the function will be called again when the loop() function is called again, this is probably the better approach. But, only you can decide which is appropriate for you.

I may give that a shot, I dunno, Thanks again for showing infinite patience and helping me though this!!

you mentioned that i could make loop1(), and loop()2 read the button state to make them switch back and forth without pushing the reset button.. what would i need to put in those loops to make them read the button state??

EDIT: I just noticed something kind of interesting...if i replace loop2() with anything else i can switch between them just fine(i tested this by replaceing the code in loop2() with the code that is in loop1() but i changed the potpin to have a different input, and when i did that i was able to push the button and control color with one pot and when i pushed the button again it was controlled with a photoresistor). so apparently there is aproblem somewhere some how with the code for the color cycle i just have no clue where to even start looking

const int  buttonPin = 2;    
const int ledPin = 13;
int ledPin2 = 12;
int rpin = 9;
int gpin = 10;
int bpin = 11;
int potpin = 0;
int buttonPushCounter = 0;   
int buttonState = 0;         
int lastButtonState = 0;
float h;                    
int h_int;                   
int r = 0, g = 0, b = 0;         
int val = 0;                   
void h2rgb(float h, int& R, int& G, int& B);  
void fadeUp(int pin, int d = 10)
{
  int i;
  for (i = 255; i >= 0; i--)
  {
    analogWrite(pin, i);
    delay(d);
  }
}
void fadeDown(int pin, int d = 20)
{
  int i;
  for (i = 0; i <= 255; i++)
  {
    analogWrite(pin, i);
    delay(d);
  }
}

void h2rgb(float h, int& R, int& G, int& B) {
  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;
  if ( S == 0 )                       
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;      
    var_i = int( var_h ) ;            
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * 255;
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
} 
void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);
  pinMode(ledPin2, OUTPUT);

  analogWrite(rpin, 255);
  analogWrite(gpin, 255);
  analogWrite(bpin, 255);
}
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
    } 
    else {
       Serial.println("off"); 
    }
    lastButtonState = buttonState;
  }
  if (buttonPushCounter % 2 == 0) {
    loop1();
  } else {
    loop2();
  }  
}
void loop1(){
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin, LOW);
  val = analogRead(potpin);   
  h = ((float)val)/1024;       
  h_int = (int) 360*h;         

  h2rgb(h,r,g,b);              
  Serial.print("POT value: ");
  Serial.print(val);           
  Serial.print(" = Hue of ");
  Serial.print(h_int);         
  Serial.print(" degrees. RGB values: ");
  Serial.print(r);             
  Serial.print(" ");
  Serial.print(g);             
  Serial.print(" ");
  Serial.println(b);           
  analogWrite(rpin, r);       
  analogWrite(gpin, g);       
  analogWrite(bpin, b);        
}

void loop2(){
  fadeUp(bpin);
  fadeUp(gpin);
  fadeDown(bpin);
  fadeUp(rpin);
  fadeDown(gpin);
  fadeUp(bpin);
  fadeDown(rpin);
}

Your loop2 function contains 4 calls to fadeUp and 3 calls to fadeDown, with the default value for delay between steps.

fadeUp has 256 steps, with 10 milliseconds between steps. That will require 2,560 milliseconds to complete.

fadeDown has 256 steps, with 20 milliseconds between steps. That will require 5,120 milliseconds to complete.

Therefore, loop2 will require 25.6 seconds to complete. You are, therefore, only able to read the button press when loop2 completes - once every 25+ seconds.

Have you tried holding the button down that long?

no i dont think i have held it down that long
EDIT: i just held it down for that long and it still didnt chang back... is this going to be easier to just push the reset button or is there something fairly simple that can be done

Since you "need" to use delay, you will probable need to look into using an interrupt to monitor the switch. When the interrupt occurs, simply increment buttonPressCounter and set a global boolean variable (stop) to true. In fadeUp and fadeDown, change the conditional part of the loop to include " && !stop":

for(i = 255; i >= 0[glow] && !stop[/glow]; i--)

After the interrupt, code resumes executing right where it left off, so, on each pass through the for loops, you need to see if the code should stop.

i am not sure how to do what your saying, I dont know what the conditional part of the loop is, i dont know how to set a global boolean variable,..