~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/6.Sensors/ADXL3xx/ADXL3xx.pde

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 4 Sep 2010
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:
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)
35
 
 
36
 
void setup()
37
 
{
38
 
  // initialize the serial communications:
39
 
  Serial.begin(9600);
40
 
  
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);
49
 
}
50
 
 
51
 
void loop()
52
 
{
53
 
  // print the sensor values:
54
 
  Serial.print(analogRead(xpin));
55
 
  // print a tab between values:
56
 
  Serial.print("\t");
57
 
  Serial.print(analogRead(ypin));
58
 
  // print a tab between values:
59
 
  Serial.print("\t");
60
 
  Serial.print(analogRead(zpin));
61
 
  Serial.println();
62
 
  // delay before next reading:
63
 
  delay(100);
64
 
}