Need help with Accelerometer

Hello,

I am new to Audrino and I have never worked with lilypad accelerometer before, but I am suppose to make a Tri color LED show different colors when the acceleromater is in shaked in different dimensions.

I have the following code written out, but it is not working. tried with both analog and digital write.

int xPin = 14;
int yPin = 15;
int zPin = 16;
int ledPinG = 9;
int ledPinB = 10;
int ledPinR = 11;

int val = 0;

void setup() {
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinR, OUTPUT);
pinMode(ledPinB, OUTPUT);
digitalWrite(xPin, HIGH);
digitalWrite(yPin, HIGH);
digitalWrite(zPin, HIGH);
}
void loop(){
val = digitalRead(xPin);//analogRead(xPin);
if(val == HIGH) {
digitalWrite(ledPinG, LOW);
} else if (val == LOW) {
digitalWrite(ledPinG, HIGH);
}

val = digitalRead(yPin); //analogRead(yPin);
if(val == HIGH) {
digitalWrite(ledPinB, LOW);
} else if (val == LOW) {
digitalWrite(ledPinB, HIGH);
}

val = digitalRead(zPin); //analogRead(zPin);
if(val == HIGH) {
digitalWrite(ledPinR, LOW);
} else if (val == LOW) {
digitalWrite(ledPinR, HIGH);
}
}

Any help?

the lilypad accelerometer outputs 0-3v so you need to use analogread, not digitalread. the value read is between 0-1024 wit h0 being 0 volts and 1024 being 5 volts. just sitting still each axis ofthe accelerometer will read 1.6 volts if it is parallel to the ground or 1.9 volts if the axes is perpindicular to the ground. just check to see if the value is greater or less than a threshold( which you will have to determine by trial and error) to decide when to turn on or offeach light. This isn't really detecting shaking but rather any movement of the accelerometer. to test for shaking you have to read the analog value multiple times and see if it is switching from above 1.6V to less than 1.6 V