1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00
Arduino/build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde

63 lines
1.7 KiB
Plaintext
Raw Normal View History

2009-07-11 02:34:59 +02:00
/*
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
created 2 Jul 2008
by David A. Mellis
modified 26 Jun 2009
by Tom Igoe
*/
// these constants describe the pins. They won't change:
2009-09-24 00:21:15 +02:00
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
2009-09-24 00:21:24 +02:00
const int xpin = 3; // x-axis of the accelerometer
2009-09-24 00:21:15 +02:00
const int ypin = 2; // y-axis
const int zpin = 1; // z-axis (only on 3-axis models)
2009-07-11 02:34:59 +02:00
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
}