RBG LED + LED fading questions

Okay so i've been playing with my arduino alot lately, mainly because i have this sweet idea for LED's, but at this stage, i'm still learning the basics.

So what I want to do is have my RGB LED hooked up and have it fade from one color of the RGB to the next (Red-Green-Blue) but have it fade to a single Red LED in between ( RED(RGB) -RED- Green(RGB) - RED - Blue(RGB) - Red - repeat) and I have this code so far.

int rPin = 9;
int gPin = 10;
int bPin = 11;
int ledPin = 13;

void fade(int r1, int g1, int b1, int r2, int g2, int b2, int led1, int led2, int t);

void setup()
{
  pinMode(rPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  fade(255,0,0,0,0,0,0,255,400);
  fade(0,0,0,255,0,255,0,0,400);
  fade(0,255,0,0,0,0,0,255,400);
  fade(0,0,0,255,0,0,255,0,400);
  fade(0,0,255,0,0,0,0,255,400);
  fade(0,0,0,255,255,0,0,0,400);
   
}
  
void fade(int r1, int g1, int b1, int led1, int r2, int g2, int b2, int led2 int t)
{
  float r_float1, g_float1, b_float1, led_float1;
  float r_float2, g_float2, b_float2, led_float2;
  float grad_r, grad_g, grad_b, grad_led;
  float output_r, output_g, output_b, output_led;
  
  r_float1 = (float) r1;
  g_float1 = (float) g1;
  b_float1 = (float) b1;
  led_float1 = (float) led1;
  r_float2 = (float) r2;
  g_float2 = (float) g2;
  b_float2 = (float) b2;
  led_float2 = (float) led2;
  
  grad_r = (r_float2-r_float1)/t;
  grad_g = (g_float2-g_float1)/t;
  grad_b = (b_float2-b_float1)/t;
  grad_led = (led_float2-led_float1)/t;
  
  
  
  analogWrite = (rPin, grad_r);
  analogWrite = (gPin, grad_g);
  analogWrite = (bPin, grad_b);
  analogWrite = (ledPin, grad_led);

I've been writing this code and been studying another code here,

[quote]
{

  [color=#CC6600]float[/color] r_float1, g_float1, b_float1;
  [color=#CC6600]float[/color] r_float2, g_float2, b_float2;
  [color=#CC6600]float[/color] grad_r, grad_g, grad_b;
  [color=#CC6600]float[/color] output_r, output_g, output_b;
  
  [color=#7E7E7E]//declare integer RGB values as float values[/color]
  r_float1 = ([color=#CC6600]float[/color]) r1;
  g_float1 = ([color=#CC6600]float[/color]) g1;
  b_float1 = ([color=#CC6600]float[/color]) b1;
  r_float2 = ([color=#CC6600]float[/color]) r2;
  g_float2 = ([color=#CC6600]float[/color]) g2;
  b_float2 = ([color=#CC6600]float[/color]) b2;
  
  [color=#7E7E7E]//calculate rates of change of R, G, and B values[/color]
  grad_r = (r_float2-r_float1)/t;
  grad_g = (g_float2-g_float1)/t;
  grad_b = (b_float2-b_float1)/t;
  
  [color=#7E7E7E]//loop round, incrementing time value "i"[/color]
  [color=#CC6600]for[/color] ( [color=#CC6600]float[/color] i=0; i<=t; i++ )
  {
    
    output_r = r_float1 + grad_r*i;
    output_g = g_float1 + grad_g*i;
    output_b = b_float1 + grad_b*i;
    
    [color=#7E7E7E]//map values - arduino is sinking current, not sourcing it[/color]
    output_r = [color=#CC6600]map[/color] (output_r,0,255,255,0);
    output_g = [color=#CC6600]map[/color] (output_g,0,255,255,0);
    output_b = [color=#CC6600]map[/color] (output_b,0,255,255,0);
    
    [color=#7E7E7E]//output[/color]
    [color=#CC6600]analogWrite[/color](rpin, ([color=#CC6600]int[/color])output_r);
    [color=#CC6600]analogWrite[/color](gpin, ([color=#CC6600]int[/color])output_g);
    [color=#CC6600]analogWrite[/color](bpin, ([color=#CC6600]int[/color])output_b);
    
    [color=#7E7E7E]//hold at this colour set for 1ms[/color]
    [color=#CC6600]delay[/color](1);
    
  }
}

[/quote]

Now the code i've been studying isn't mine, i found it on another topic post.

Anyway, I don't understand exactly what the float is, and what the map is, and why I need void solid. I just don't get like the math grammer when dealing with it. Like how does the void solid interact with the void fade, and what is the "i" thing?

Please help me, I have alot of question!!

You need to post the second sketch again without the colour information.

I don't understand exactly what the float is

A "float" is a non-integer data type, capable of storing fractions, so an "int" can only hold, say 356, but a float could hold a representation of 354.74

I have also looked into fading RGB LEDs. I have modified the first piece of code you were using for my own purpose and in the process simplified and heavily commented it. Some of the changes and comments might make it easier for you to use.

//i/o pin declarations setting the arduino pin values of the rgb led
#define rpin 9
#define gpin 10
#define bpin 11

  int r1=0;//sets three numbers to 0. 
  int g1=0;// These are the origin #s, hence r1, g1,b1.
  int b1=0;
  
void setup()		    
{
  pinMode(rpin,OUTPUT);//An arduino formality, we declare the pins
  pinMode(gpin,OUTPUT);//as ouputs for voltage.
  pinMode(bpin,OUTPUT);
}
/*
This is what the program does:
Tt starts the rgb led at full off. It then picks three random numbers
which correspond to a random color. It then finds the difference between the origin #s
and the destination #s for each color and divides it by time resulting in a number which represents 
the increment which will be added "time" times to reach the destination number. In 1 millisecond increments
a counter approaches the time set in the time variable. The counting variable is 
multiplied by the increment and added to the origin. It will approach the destination in "time" steps
of the incrementr. Finally, when the destination color is reached,
the destination is set as the new origin, and a new random destination is selected.
This program contians valuable fade functions which can be used for many applications
besides random color fading.
*/

void loop()//This is an arduino specific infinite loop. basically 
{          // the same thing as while (1==1){do stuff}	
		  
              //Fades between random colors.

  int r2=random(0,255);//Generates 3 "random" destination numbers between 0 and 255.
  int g2=random(0,255);//Hence r2,g2,b2.
  int b2=random(0,255);
 fade(r1,g1,b1,r2,g2,b2,random(500,5000));//fades between the two sets of random numbers
 r1=r2;//sets the destination #'s as the origin #'s
 g1=g2;//this allows the colors to continue changing without jumps.
 b1=b2;
 
 
 //           Fades between primary colors
 /*
 fade(0,0,255,0,255,0,2500);//fades from 0,0,255(blue) to 0,255,0(green, over 2.5 seconds
 fade(0,255,0,255,0,0,2500);//fades from 0,255,0(Green) to 255,0,0(red) over 2.5 seconds
 fade(255,0,0,0,0,255,2500);//fades from 255,0,0(red) to 0,0,255(blue) over 2.5 seconds
 */
 /*
      // Fades between primary and seocndary colors
// I split the sections for ease of use,
 //the compiler ignores empty space
 
 fade(0,0,255,        0,128,128,2500);//blue to cyan
 fade(0,128,128,      0,255,0,2500);//cyan to green
 fade(0,255,0,        128,128,0,2500);//green to orange
 fade(128,128,0,      255,0,0,2500);//orange to red
 fade(255,0,0,        128,0,128,2500);//red to purple
 fade(128,0,128,      0,0,255,2500);//purple to blue
 */

}

//function fades between two RGB values over fade time period t
//maximum value of fade time = 30 seconds before gradient values
//get too small for floating point math to work? replace floats
//with doubles to remedy this?
void fade(int r1, int g1, int b1, int r2, int g2, int b2, int t)
{
  float r_float1, g_float1, b_float1;//creates three origin floats
  float r_float2, g_float2, b_float2;//creates three destination floats
  float grad_r, grad_g, grad_b;//creates three increment floats
  float output_r, output_g, output_b;//creates three brightness floats
  
  //sets internal floats to the external inputs of the function
 //thisa is done to fully seperate the function form the rest of the program
  r_float1 = (float) r1;
  g_float1 = (float) g1;
  b_float1 = (float) b1;
  r_float2 = (float) r2;
  g_float2 = (float) g2;
  b_float2 = (float) b2;
  
  //calculate rates of change of R, G, and B values
  grad_r = (r_float2-r_float1)/t;//This is the increment by which the brightness
  grad_g = (g_float2-g_float1)/t;//value will millisecond
  grad_b = (b_float2-b_float1)/t;
  //loop round, incrementing time value "i"
  //counts to time(a # in milliseconds) in one millisecond increments
  for ( float i=0; i<=t; i++ )
  {
  output_r = r_float1 + grad_r*i;//sets the 0-255 brightness output for each color
  output_g = g_float1 + grad_g*i;//as the origin and then adds 
  output_b = b_float1 + grad_b*i;//the appropriate increment times i
  /*
  Normally with an LED, an I/O pin is connected to the positive anode
  through a resisitor and then out the cathode to ground.
  However, with a common cathode RGB LED, the three LEDs source(take)
  current from one shared +5v source. While there is one(common) anode
  Each LED has its own cathode(ground/negative) so that it can be 
  individually controlled. These cathodes are connected through a 270ohm
  resisitor to three individual digital PWM pins. In order for 
  the individual LEDs to light up, there must be a voltage drop across them. 
  So if the digital pin is high, and the anode is high,(meaning~+5v)
  there is no drop across the LED and no light. While analogWrite is
  different from digitalWrite, It involves setting a pin high or low(0volts)
  at a set frequency. 255 means on high all of the time and therefore
  the LED will be off. 0 means off all of the time and therefore the LED on. 
  Here we set output_r=255-output_r as a way to inverse the values 
  so they correspond to 255 on and 0 off.
  */
    output_r = 255-output_r;
    output_g = 255-output_g;
    output_b = 255-output_b;
    
    //outputs to the LEDs while casting the floating point number into an integer
    // for ease of use by the function analogWrite
    //see the void function rgb_color_write below
    rgb_color_write((int)output_r,(int)output_g,(int)output_b);
    //hold at this colour set for 1ms
    delay(1);
  }
}
//function to simplify driving an RGB LED
//takes three brightness values and rights them
void rgb_color_write(int rval, int gval, int bval)
{
 analogWrite(rpin,rval);
 analogWrite(gpin,gval);
 analogWrite(bpin,bval);
}

Can you provide more information about your setup? I gather that you have one RGB LED and one red LED. If this is true, you don't need to do anything fancy with the red LED, only digitalWrite statements. I hope this helps. As in regards to "i" it is usually used as the increment in a for loop,http://arduino.cc/en/Reference/For.

Also you are using 13 as your red LED. It is not PWM, so no fade.