source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 3 years ago

Adding new version

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