Adding fade to this RGB LED IMU
You need to be a little clearer about the time that can exist between the sensor values changing. If you fade to slowly the correct value might never be reached before the sensor changes again. Maybe that's what you want?

You can't use a delay().

You need a currentRed, currentGreen and currentBlue so you can fade to the values of red, green and blue.

unsigned long last_reading_ms;
int red = 255;   // Variables to store the TARGET rgb target values for each pin
int green = 255;
int blue = 255;
int currentRed = 0;   // Variables to store the current rgb values of the pins
int currentGreen = 0;
int currentBlue = 0;

void setup()
{
   last_reading_ms=millis();
}

void loop()
{
  /* read sensor every 100ms and set red, green,blue if changed */
  if (millis()-last_reading_ms &gt; 100)
  {
    /* Get a new sensor event */
    sensors_event_t event;
    accel.getEvent(&amp;event);
    //the rest of your sensor reading code here

    last_reading_ms=millis()
  }

  /* if orientation changes, print out a description */
  if (orientation != lastOrientation) {
   Serial.println(orientationString);
   lastOrientation = orientation;
  }

  calculateRGBFadeTo();

  analogWrite(redLEDPin, currentRed);   // Write values to LED pins
  analogWrite(greenLEDPin, currentGreen); 
  analogWrite(blueLEDPin, currentBlue);  


  //*** do not use a delay or use a very small one to slow the transition ***
  //delay(100);

}

/* get values 1 step closer to target red, green, blue */ 
void calculateRGBFadeTo()
{
  /* fade to required rgb values */
  if (currentRed&lt;red)
   currentRed ++;
  else if (currentRed&gt;red)
   currentRed --;

  if (currentGreen&lt;green)
    currentGreen ++;
  else if (currentGreen&gt;green)
    currentGreen --;

  if (currentBlue&lt;blue)
    currentBlue ++;
  else if (currentBlue&gt;blue)
    currentBlue --;    

}


Notes: 

The fade can be slowed down either with a small delay such as 5 ms. or by using another millis() variable to determine the time since the led was last set. 

For example: if (millis()-last_rgb_write_ms &gt; 5) 

It's also possible to speed up the fade by using a larger increment. An increment of two, for example, currentRed+=2; instead of currentRed++;

Reminder, the comparison of when the target red, green, blue has been reached will be more complex with an increment greater than 1. 

An increment of 2 and a sensor read frequency of 128ms (instead of 100) would ensure the correct RGB values are always reached. Alternatively reading the sensor every 255ms (4-5 times per second) would also ensure the correct RGB values has been reached.

Using millis() and avoiding delays allows many more tasks to be performed with more accurate timings.