4
Read the Memsic 2125 two-axis accelerometer. Converts the
5
pulses output by the 2125 into milli-g's (1/1000 of earth's
6
gravity) and prints them over the serial connection to the
10
* X output of accelerometer to digital pin 2
11
* Y output of accelerometer to digital pin 3
12
* +V of accelerometer to +5V
13
* GND of accelerometer to ground
15
http://www.arduino.cc/en/Tutorial/Memsic2125
22
This example code is in the public domain.
26
// these constants won't change:
27
const int xPin = 2; // X output of the accelerometer
28
const int yPin = 3; // Y output of the accelerometer
31
// initialize serial communications:
33
// initialize the pins connected to the accelerometer
40
// variables to read the pulse widths:
42
// variables to contain the resulting accelerations
43
int accelerationX, accelerationY;
45
// read pulse from x- and y-axes:
46
pulseX = pulseIn(xPin,HIGH);
47
pulseY = pulseIn(yPin,HIGH);
49
// convert the pulse width into acceleration
50
// accelerationX and accelerationY are in milli-g's:
51
// earth's gravity is 1000 milli-g's, or 1g.
52
accelerationX = ((pulseX / 10) - 500) * 8;
53
accelerationY = ((pulseY / 10) - 500) * 8;
55
// print the acceleration
56
Serial.print(accelerationX);
57
// print a tab character:
59
Serial.print(accelerationY);