Arduino Accelerometer (ADXL330)

Another toy I ordered quite awhile ago was an accelerometer. Just hooked it up, no sweat. Here's the code:
#define xPin 5
#define yPin 4
#define zPin 3
int x = 0;
int y = 0;
int z = 0;
int delta = 0;

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

void loop() {
delta = x + y + z;
x = analogRead(xPin);
y = analogRead(yPin);
z = analogRead(zPin);
delta -= x + y + z;
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.print(", ");
Serial.print(z);
Serial.print(", ");
Serial.println(abs(delta));
delay(500);
}

No comments:

Post a Comment