5
Reads an Analog Devices ADXL3xx accelerometer and communicates the
6
acceleration to the computer. The pins used are designed to be easily
7
compatible with the breakout boards from Sparkfun, available from:
8
http://www.sparkfun.com/commerce/categories.php?c=80
10
http://www.arduino.cc/en/Tutorial/ADXL3xx
13
analog 0: accelerometer self test
25
This example code is in the public domain.
29
// these constants describe the pins. They won't change:
30
const int groundpin = 18; // analog input pin 4 -- ground
31
const int powerpin = 19; // analog input pin 5 -- voltage
32
const int xpin = A3; // x-axis of the accelerometer
33
const int ypin = A2; // y-axis
34
const int zpin = A1; // z-axis (only on 3-axis models)
38
// initialize the serial communications:
41
// Provide ground and power by using the analog inputs as normal
42
// digital pins. This makes it possible to directly connect the
43
// breakout board to the Arduino. If you use the normal 5V and
44
// GND pins on the Arduino, you can remove these lines.
45
pinMode(groundpin, OUTPUT);
46
pinMode(powerpin, OUTPUT);
47
digitalWrite(groundpin, LOW);
48
digitalWrite(powerpin, HIGH);
53
// print the sensor values:
54
Serial.print(analogRead(xpin));
55
// print a tab between values:
57
Serial.print(analogRead(ypin));
58
// print a tab between values:
60
Serial.print(analogRead(zpin));
62
// delay before next reading: