Accelerometer data into RGB led values

OK, I have the code and everything works except that the led flickers and does not have a constance change of hue. Is there any way to make the led change value consistantly instead of jumping from value to value.Here is a video for your debugging convenience.http://vimeo.com/4287078

and here is the code that I am using

int Rled = 9;
int Gled = 10;
int Bled = 11;
int Xpin = 0;
int Ypin = 1;
int Zpin = 2;

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

pinMode(Rled, OUTPUT);
pinMode(Gled, OUTPUT);
pinMode(Bled, OUTPUT);
}

void loop()
{
int x = analogRead(Xpin);
int y = analogRead(Ypin);
int z = analogRead(Zpin);

x = map(x, 268, 405, 0, 255);
y = map(y, 270, 420, 0, 255);
z = map(z, 354, 450, 0, 255);

Serial.print("X ");
Serial.print(x);
Serial.print(" Y ");
Serial.print(y);
Serial.print(" Z");
Serial.println(z);

analogWrite(Rled, x);
analogWrite(Gled, y);
analogWrite(Bled, z);

}

Maybe some smoothing will help.
[UNTESTED CODE]

/*
|| AccelRGB
||
|| @contribution
|| | sburry
|| | AlphaBeta
|| #
*/

#define AVARAGE_READINGS 10

int Rled = 9;
int Gled = 10;
int Bled = 11;
int Xpin = 0;
int Ypin = 1;
int Zpin = 2;

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

pinMode(Rled, OUTPUT);
pinMode(Gled, OUTPUT);
pinMode(Bled, OUTPUT);
}

void loop()
{
int x = analogRead(Xpin);
int y = analogRead(Ypin);
int z = analogRead(Zpin);
for (byte i=0; i<AVARAGE_READINGS; i++){
x += analogRead(Xpin);
x /= 2;
y += analogRead(Ypin);
y /= 2;
z += analogRead(Zpin);
z /= 2;
}

x = map(x, 268, 405, 0, 255);
y = map(y, 270, 420, 0, 255);
z = map(z, 354, 450, 0, 255);

Serial.print("X ");
Serial.print(x);
Serial.print(" Y ");
Serial.print(y);
Serial.print(" Z");
Serial.println(z);

analogWrite(Rled, x);
analogWrite(Gled, y);
analogWrite(Bled, z);
}

except that the led flickers and does not have a constance change of hue

So why not have a variable for the value of each colour. Then each time round the loop look at what the distance transducer is telling you (the target) and work out how far you are away from that value. Then increment the value if you are below the target or decrement it if you are above. You will do this three times one for each colour.
Then put a delay before the next loop.

The delay will control how quickly the LEDs respond.

If you're holding an accelerometer by hand, the changes in acceleration are very short-lived. A spike when you begin to move your hand, a spike in the opposite direction when you stop your hand. That's why you're getting flickers.

You might want to look at my playground code, Arduino Playground - ADXL330 - it uses an accelerometer and it models a "mood" for it, a numeric level of agitation that decays over time. Shaking the device increases the agitation in the mood. Letting it rest will reduce the agitation in the mood. Then it describes the mood using RGB colors: a red and fast "angry" heartbeat down to a blue and calm "serene" heartbeat.