How switch between 2 different codes?

Hi!

So, I have one arduino and led matrix, what is direcly connected to board.

My plan is use 2 atmega168 with 2 different codes, than switch between atmega using pushbutton. (maybe ar some link on tutorial)

What is easier way? Hardware(use two atmega) or Software(2 codes in 1 atmega and switch between codes with pushbutton) ?

At board free pins are all POWER, 4,5 ANALOG IN and 1,2 DIGITAL

software.

just do something in the main loop like

pseudocode ahead:

if(digitalRead(0))
{
do code 1;
}

else
{
do code 2;
}

where you replace "do code" with the code you want to run as if it were in the main loop...well, it is. but im just trying to generalize

No
The loop of my project is unusable, becouse i need switch between this codes when i want it.

The loop of my project is unusable, becouse i need switch between this codes when i want it.

No the loop is exactly the perfect place to do this.

Say your button is on pin 0. Your code would look something like this.

int programState = 0;

void loop()
{
   if(digitalRead(0)) //Button is pressed
   {
      programState = 1 - programState; //Flip-Flop state between 0 and 1
   }

   if(programState == 0) //Check to see which state to run
   {
      callFunctionForCode1(); //Do your cool LED dance 1 here
   } else {
      callFunctionForCode2(); //Do your cool LED dance 2 here
   }
}

Then each time you press the button it would change which code runs. The only possible downside to this is that if you are using delay() a lot in your code for the LED matrix then you have to hold the button until the end. So you need to use a Timer library to do your timing differently (better!).

Tell us more about the job you are trying to do, leaving out the details of how it might be done.

I "get": There's going to be an LCD panel showing SOMETHING
There's a selector switch.

What I don't get is WHAT is going to be showing on the LCD.

How would i need to write this if i want the code to change when a high is placed on digital pin 2 i have two codes i am wanting to do this with
these are the codes:
code1

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;
  }
}

code 2

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables set as integer (number) type
int redLEDValue   = 255; // Variables to store the values to send to the pins
int greenLEDValue = 1;   // Initial values are Red full, Green and Blue off
int blueLEDValue = 1;  // These values get passed to the analogWrite() function.
int i = 0;     // Loop counter

//setup the pins/ inputs & outputs
void setup()
{
pinMode(redPin, OUTPUT);   // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

// Main program, count to 763, a third of the way switch the incrementing of the LEDs
void loop()
{
i += 2;      // Increment counter
if (i < 255) // First phase of fades
{
redLEDValue -= 1; // Red down
greenLEDValue += 1; // Green up
blueLEDValue = 1; // Blue low
}
else if (i < 509) // Second phase of fades
{
redLEDValue = 1; // Red low
greenLEDValue -= 1; // Green down
blueLEDValue += 1; // Blue up
}
else if (i < 763) // Third phase of fades
{
redLEDValue += 1; // Red up
greenLEDValue = 1; // Green low
blueLEDValue -= 1; // Blue down
}
else // Re-set the counter, and start the fades again
{
i = 1;
}// analogWrite() expects 2 parameters, the object/pin and a value between 0 (off) and 255 (full on)
analogWrite(redPin,   redLEDValue);   // Write current values to LED pins
analogWrite(greenPin, greenLEDValue);
analogWrite(bluePin,  blueLEDValue);

delay(50); // Pause for xx milliseconds before resuming the loop
}

I read this post over and over and just couldent figure this out.. I have no clue how to write the codes..

Put all the code to one thing into one function, and all the code to do the other thing into a second function.

Then call one or the other depending on the value read from the pin.

Please don't cross-post.

Thanx i wasent wanting to cross post this just seemed like a more corect thread to post this in.. sorry

A mod can move posts if really necessary, but often it is not a big problem.

I tried copying the code from one into the code supplied in a prevous post for pin 0 i copied it in this part of his code

callFunctionForCode1();

I deleted the callFunctionForCode1 and pasted the code right before the (), and in the middle of the (), and right after the (). i just kept getting a error message saying
a function definition is not allowed here

and pasted the code right before the (), and in the middle of the (), and right after the ().

:-?

like this

int programState = 0;

void loop()
{
   if(digitalRead(0)) //Button is pressed
   {
      programState = 1 - programState; //Flip-Flop state between 0 and 1
   }

   if(programState == 0) //Check to see which state to run
   {
      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;
  }
}(); //Do your cool LED dance 1 here
   } else {
      // Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables set as integer (number) type
int redLEDValue   = 255; // Variables to store the values to send to the pins
int greenLEDValue = 1;   // Initial values are Red full, Green and Blue off
int blueLEDValue = 1;  // These values get passed to the analogWrite() function.
int i = 0;     // Loop counter

//setup the pins/ inputs & outputs
void setup()
{
pinMode(redPin, OUTPUT);   // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

// Main program, count to 763, a third of the way switch the incrementing of the LEDs
void loop()
{
i += 2;      // Increment counter
if (i < 255) // First phase of fades
{
redLEDValue -= 1; // Red down
greenLEDValue += 1; // Green up
blueLEDValue = 1; // Blue low
}
else if (i < 509) // Second phase of fades
{
redLEDValue = 1; // Red low
greenLEDValue -= 1; // Green down
blueLEDValue += 1; // Blue up
}
else if (i < 763) // Third phase of fades
{
redLEDValue += 1; // Red up
greenLEDValue = 1; // Green low
blueLEDValue -= 1; // Blue down
}
else // Re-set the counter, and start the fades again
{
i = 1;
}// analogWrite() expects 2 parameters, the object/pin and a value between 0 (off) and 255 (full on)
analogWrite(redPin,   redLEDValue);   // Write current values to LED pins
analogWrite(greenPin, greenLEDValue);
analogWrite(bluePin,  blueLEDValue);

delay(50); // Pause for xx milliseconds before resuming the loop
}
(); //Do your cool LED dance 2 here
   }
}

and i just get an error

Hilbilly, don't become discouraged by mere details. The basic structure for such tasks is this, easily extendable to more than 2 variants.

byte theMode =0;

void setup() {
  //leave empty!
}

void loop() {
  switch (modeRequest()) {
    case 1:
      if (theMode ==2) {
        stop2();
        setup1();
        theMode=1
        }
      loop1();
      break
      
    case 2:
      if (theMode ==1) {
        stop1();
        setup2();
        theMode=2
        }
      loop2();
      break
  } //end switch
} //end proc

and where exactly would i paste my code into on that?

OK I have tried every freaking thing I can think of I do not understand where I am supposed to put the codes... I am at a complete loss and do not know what to do. I do not care what pin the button signal is sent to all i want is to be able to switch between the two codes with a switch.
code1

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;
  }
}

code2

/*************************** 
Author: Seth Leeper 
Version: 1 
Purpose: To cycle the tri-color LED 
contained within the Sparkfun starter kit 
through every available color combination with 
a fade in/fade out effect. 
************************************/ 

int RED = 9;    // RED pin of the LED to PWM pin 9 
int GREEN = 10;  // GREEN pin of the LED to PWM pin 10 
int BLUE = 11;   // BLUE pin of the LED to PWM pin 11 

int DELAY_TIME = 50;  //changes speed of fading 
int MAX_BRIGHT = 255; //sets maximum brightness, 255 max brightness 
int COLOR_MIX = 0; //variable to change the colors that are mixed in switch statement 

void fade_in(int x) //loop that gradually turns the LED on using PWM 
{ 
    int counter; 
    
    for(counter = 0; counter < x; counter++) 
    { 
        led_mixer(COLOR_MIX, counter); 
        delay(DELAY_TIME); 
    } 
} 

void fade_out(int x) //loop that gradually turns the LED off using PWM 
{ 
    int counter; 
    
    for(counter = x; counter > 0; counter--) 
    { 
        led_mixer(COLOR_MIX, counter); 
        delay(DELAY_TIME); 
    } 
} 

void led_mixer(int color, int x) //uses switch statement to mix color combinations 
{ 
    switch(color) 
    { 
      case 0: 
        analogWrite(RED, x); 
        break; 
      case 1: 
        analogWrite(GREEN, x); 
        break; 
      case 2: 
        analogWrite(BLUE, x); 
        break; 
      case 3: 
        analogWrite(BLUE, x); 
        analogWrite(GREEN, x); 
        break; 
      case 4: 
        analogWrite(RED, x); 
        analogWrite(BLUE, x); 
        break; 
      case 5: 
        analogWrite(RED, x); 
        analogWrite(GREEN, x); 
        break; 
      default: 
        analogWrite(GREEN, x); 
        analogWrite(BLUE, x); 
        analogWrite(RED, x); 
      break; 
    } 
} 

void setup() 
{ 
  // nothing for setup 
} 

void loop() //loop forever 
{ 
  fade_in(MAX_BRIGHT); //gradually turn the LED on to max brightness 
  fade_out(MAX_BRIGHT); //gradually turn off the LED 
  COLOR_MIX++; //increment to the next color combination 
  
  if(COLOR_MIX == 7) //if all color combinations have been displayed, reset the cycle 
  { 
    COLOR_MIX = 0; 
  } 
}

Combining the two sketches is pretty simple.

Create a new sketch. Copy all the global variables from both sketches into the new sketch.

Copy the setup() function from one sketch into the new sketch, and include any non-duplicate code from the other setup() function. Since one setup function initializes serial communication, and the other one does nothing, the resulting setup function will just initialize serial communications.

Now, copy the loop function from one sketch into the new sketch, and rename it to something like loop1. Copy the loop function from the other sketch, and rename it to something like loop2.

Copy all the other functions from both sketches into the new sketch.

Finally, in the new sketch, create a loop function. In that function, read (and debounce) a switch. Toggle the state of a boolean variable. Then, call loop1 if the variable is true. Otherwise call loop2.

boolean wayOne = true;
void loop()
{
   if(digitalRead(somePin) == HIGH)
   {
      wayOne = !wayOne;
   }

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

ok this is what i came up with.. and i just get an error I cannot figure this out!!!

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 readPin = 3;
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




int RED = 9;    // RED pin of the LED to PWM pin 9 
int GREEN = 10;  // GREEN pin of the LED to PWM pin 10 
int BLUE = 11;   // BLUE pin of the LED to PWM pin 11 

int DELAY_TIME = 50;  //changes speed of fading 
int MAX_BRIGHT = 255; //sets maximum brightness, 255 max brightness 
int COLOR_MIX = 0; //variable to change the colors that are mixed in switch statement 
pinMode(readPin, INPUT);
void fade_in(int x) //loop that gradually turns the LED on using PWM 
{ 
    int counter; 
    
    for(counter = 0; counter < x; counter++) 
    { 
        led_mixer(COLOR_MIX, counter); 
        delay(DELAY_TIME); 
    } 
} 

void fade_out(int x) //loop that gradually turns the LED off using PWM 
{ 
    int counter; 
    
    for(counter = x; counter > 0; counter--) 
    { 
        led_mixer(COLOR_MIX, counter); 
        delay(DELAY_TIME); 
    } 
} 

void led_mixer(int color, int x) //uses switch statement to mix color combinations 
{ 
    switch(color) 
    { 
      case 0: 
        analogWrite(RED, x); 
        break; 
      case 1: 
        analogWrite(GREEN, x); 
        break; 
      case 2: 
        analogWrite(BLUE, x); 
        break; 
      case 3: 
        analogWrite(BLUE, x); 
        analogWrite(GREEN, x); 
        break; 
      case 4: 
        analogWrite(RED, x); 
        analogWrite(BLUE, x); 
        break; 
      case 5: 
        analogWrite(RED, x); 
        analogWrite(GREEN, x); 
        break; 
      default: 
        analogWrite(GREEN, x); 
        analogWrite(BLUE, x); 
        analogWrite(RED, x); 
      break; 
    } 
} 

void setup()
{
  Serial.begin(9600);
}




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

   if(wayOne)
      void loop(1);
   else
      void loop(2);
} 




void loop(1)                     // 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;
  }
}


void loop(2) //loop forever 
{ 
  fade_in(MAX_BRIGHT); //gradually turn the LED on to max brightness 
  fade_out(MAX_BRIGHT); //gradually turn off the LED 
  COLOR_MIX++; //increment to the next color combination 
  
  if(COLOR_MIX == 7) //if all color combinations have been displayed, reset the cycle 
  { 
    COLOR_MIX = 0; 
  } 
}

I have chaged to a different code for the auto color cycling... i am going to try it out... it seems more straight forward and maybe i can get this working

int redPin = 9;
int greenPin = 10;
int bluePin = 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(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  analogWrite(redPin, 255);
  analogWrite(greenPin, 255);
  analogWrite(bluePin, 255);

  fadeUp(bluePin);
}


void loop()
{
  fadeUp(greenPin);
  fadeDown(bluePin);
  fadeUp(redPin);
  fadeDown(greenPin);
  fadeUp(bluePin);
  fadeDown(redPin);
}

ok useing the new fader code here is what i have come up with for combining these two

int rpin = 9;
int gpin = 10;
int bpin = 11;
int potpin = 2;
int readPin = 3;
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 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);

  fadeUp(bpin);
}

boolean wayOne = true;

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

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

as it stands now the only error i am getting is that "loop1() is not declared in this scope" which i expected... but every thing before that is working so i am assuming that is is in there correctly.. my question now it how to i name the void loop for one of the codes "loop1()" where do i need to paste the code?

my question now it how to i name the void loop for one of the codes "loop1()" where do i need to paste the code?

Copy the loop function out of one of the old sketches, and paste it at the bottom of this sketch.

Then, scroll back to the top of the pasted code. Position the cursor between the p and the ( and type a 1. The function now has a new name.

Do the same for the other old sketch, except type a 2.