How to correctly code a LED STRIP?
The main difference between what you want and what that code does is that you want to fade both colours at once, but that code is aimed at only fading one colour at a time.

You want to fade R up whilst fading B down, and then fade R down whilst fading B up. The simplest way is with just two loops:

// Fade red up and blue down
for (int i = 0; i &lt; 256; i++) { 
  analogWrite(REDPIN, i);
  analogWrite(BLUEPIN, 255 - i);
  delay(FADESPEED);
} 

// Fade red down and blue up
for (int i = 0; i &lt; 256; i++) { 
  analogWrite(REDPIN, 255 - i);
  analogWrite(BLUEPIN, i);
  delay(FADESPEED);
} 


One fade value (i) per loop, and a little bit of maths to turn 0-255 into 255-0 for the value you are fading down.



For Red->Yellow->Red you just need to keep red on and fade green on and off.  You already have code to fade green on and off in your original program:

  // fade from red to yellow
  for (g = 0; g &lt; 256; g++) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 

  // fade from teal to blue
  for (g = 255; g &gt; 0; g--) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 


Couple that with setting the red and blue to on and off respectively, and you have:

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

#define FADESPEED 5     // make this higher to slow down

void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);

  analogWrite(REDPIN, 255);
  analogWrite(BLUEPIN, 0);
}

void loop() {
  int g;

  // fade from red to yellow
  for (g = 0; g &lt; 256; g++) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 

  // fade from yellow to red
  for (g = 255; g &gt; 0; g--) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 
}