| 1 |
/* |
| 2 |
ADXL3xx |
| 3 |
|
| 4 |
Reads an Analog Devices ADXL3xx accelerometer and communicates the |
| 5 |
acceleration to the computer. The pins used are designed to be easily |
| 6 |
compatible with the breakout boards from SparkFun, available from: |
| 7 |
https://www.sparkfun.com/categories/80 |
| 8 |
|
| 9 |
The circuit: |
| 10 |
- analog 0: accelerometer self test |
| 11 |
- analog 1: z-axis |
| 12 |
- analog 2: y-axis |
| 13 |
- analog 3: x-axis |
| 14 |
- analog 4: ground |
| 15 |
- analog 5: vcc |
| 16 |
|
| 17 |
created 2 Jul 2008 |
| 18 |
by David A. Mellis |
| 19 |
modified 30 Aug 2011 |
| 20 |
by Tom Igoe |
| 21 |
|
| 22 |
This example code is in the public domain. |
| 23 |
|
| 24 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ADXL3xx |
| 25 |
*/ |
| 26 |
|
| 27 |
// these constants describe the pins. They won't change: |
| 28 |
const int groundpin = 18; // analog input pin 4 -- ground |
| 29 |
const int powerpin = 19; // analog input pin 5 -- voltage |
| 30 |
const int xpin = A3; // x-axis of the accelerometer |
| 31 |
const int ypin = A2; // y-axis |
| 32 |
const int zpin = A1; // z-axis (only on 3-axis models) |
| 33 |
|
| 34 |
void setup() { |
| 35 |
// initialize the serial communications: |
| 36 |
Serial.begin(9600); |
| 37 |
|
| 38 |
// Provide ground and power by using the analog inputs as normal digital pins. |
| 39 |
// This makes it possible to directly connect the breakout board to the |
| 40 |
// Arduino. If you use the normal 5V and GND pins on the Arduino, |
| 41 |
// you can remove these lines. |
| 42 |
pinMode(groundpin, OUTPUT); |
| 43 |
pinMode(powerpin, OUTPUT); |
| 44 |
digitalWrite(groundpin, LOW); |
| 45 |
digitalWrite(powerpin, HIGH); |
| 46 |
} |
| 47 |
|
| 48 |
void loop() { |
| 49 |
// print the sensor values: |
| 50 |
Serial.print(analogRead(xpin)); |
| 51 |
// print a tab between values: |
| 52 |
Serial.print("\t"); |
| 53 |
Serial.print(analogRead(ypin)); |
| 54 |
// print a tab between values: |
| 55 |
Serial.print("\t"); |
| 56 |
Serial.print(analogRead(zpin)); |
| 57 |
Serial.println(); |
| 58 |
// delay before next reading: |
| 59 |
delay(100); |
| 60 |
} |